Get Files from Directory [C#]

This example shows how to get list of file names from a directory (includingsubdirectories).

You can filter the list by specific extension.


To get file names from the specified directory, use static method

Directory.Get­Files.

Lets have these files andsubfolders in „c:\MyDir“ folder:

Get files from directory

Method Directory.GetFiles returns string array with files names (fullpaths).

[C#]

 using System.IO;  

   string[] filelist = Directory.GetFiles(@"D:\迅雷下载");
            foreach (var f in filelist)

richTextBox1.AppendText(f + "\r\n");


 

Get files from directory (with specified extension)

You can specify search pattern. You can use wildcard specifiers in the searchpattern,

e.g. „*.bmp“ to select files with the extension or „a*“ toselect files beginning with letter „a“.

[C#]


            string[] filelist = Directory.GetFiles(@"D:\迅雷下载\","*.zip");
            foreach (var f in filelist)

richTextBox1.AppendText(f + "\r\n");

 
获得文件夹下的指定文件列表(只找一层)

 

Get files from directory (including all subdirectories)

If you want to search also in subfolders use parameterSearchOption.A­llDirectories.

[C#]


            string[] filelist = Directory.GetFiles(@"D:\迅雷下载\", "*.*",SearchOption.AllDirectories);
            foreach (var f in filelist)

richTextBox1.AppendText(f + "\r\n");


 
 


Get Files from Directory的更多相关文章

  1. Hive:org.apache.hadoop.hdfs.protocol.NSQuotaExceededException: The NameSpace quota (directories and files) of directory /mydir is exceeded: quota=100000 file count=100001

    集群中遇到了文件个数超出限制的错误: 0)昨天晚上spark 任务突然抛出了异常:org.apache.hadoop.hdfs.protocol.NSQuotaExceededException: T ...

  2. How do I list the files in a directory?

    原文地址:How do I list the files in a directory? You want a list of all the files, or all the files matc ...

  3. Apache 容器 Directory Location Files 及htaccess文件

    配置段容器的类型 相关模块 core mod_proxy 相关指令 <Directory> <DirectoryMatch> <Files> <FilesMa ...

  4. I can connect to an FTP site but I can't list or transfer files.

    原文 FTP sessions use two network connections: The control channel is for user authentication and send ...

  5. Debugging Information in Separate Files

    [Debugging Information in Separate Files] gdb allows you to put a program's debugging information in ...

  6. How to Use Rsync to Sync New or Changed/Modified Files in Linux

    As a system administrator or Linux power user, you may have probably come across or even on several ...

  7. 10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

    The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk ...

  8. How To Get Log, Trace Files In OA Framework Pages And Concurrent Request Programs

    Goal   Solution   References APPLIES TO: Oracle Supplier Lifecycle Management - Version 12.1.2 and l ...

  9. 详解:基于WEB API实现批量文件由一个服务器同步快速传输到其它多个服务器功能

    文件同步传输工具比较多,传输的方式也比较多,比如:FTP.共享.HTTP等,我这里要讲的就是基于HTTP协议的WEB API实现批量文件由一个服务器同步快速传输到其它多个服务器这样的一个工具(简称:一 ...

随机推荐

  1. 使用simhash以及海明距离判断内容相似程度

    算法简介 SimHash也即相似hash,是一类特殊的信息指纹,常用来比较文章的相似度,与传统hash相比,传统hash只负责将原始内容尽量随机的映射为一个特征值,并保证相同的内容一定具有相同的特征值 ...

  2. Tomcat 配置问题总结

    本人是一个前端屌丝儿,最近没事研究了一下tomcat的部署问题,一下列几个实用的小技能(直接上干货了,不赘述): 1,路径引用部署 在tomcat目录下的conf/Catalina/localhost ...

  3. BZOJ3688: 折线统计

    题解: 令f[i][j][0/1]表示前i个数有j段,最后一段是下降/上升的方案数 很容易列出状态转移方程(已按x轴排序) f[i][j][0]=sigma(f[k][j][0]+f[k][j-1][ ...

  4. Spring编程风格

    给自己使用的无需定义接口:即一个模块内部的都是封装的,定义接口并不会得到很多好处,变过几次实现?? “优先面向接口编程,而非实现” 不是必须,是优先: 给朋友(第三方)使用的定义接口:即要公开的功能, ...

  5. 教你用Java安全有效的实现两星期内自动登陆功能-Session

    现在很多网站都有为用户保存登陆信息(即保存Cookie)的功能,当用户下一次进入网站时,可以帮助用户自动登陆,使网站显得更加友好.笔者通过研究ACEGI项目的自动登陆源码,编写了一个安全有效的实现两星 ...

  6. MFC定时器使用

    MFC定时器实现方法 方法一:CWnd类提供的成员函数SetTimer实现定时器功能,只能在CWnd类或其派生类中调用. 方法二:Windows API函数SetTimer来实现. MFC定时器 启动 ...

  7. ADB 远程无线调试

    由于自己购买的x4412 Android开发板存在一个问题,是无法同时链接USB线,和插入无线网卡.只能使用其中一个功能 需要复现一个DRM在线下载的功能,同时需要抓起一些日志信息,此处就想到了使用 ...

  8. oracle 启用归档日志

    Oracle可以运行在2种模式下:归档模式(archivelog)和非归档模式(noarchivelog) 归档模式可以提高Oracle数据库的可恢复性,生产数据库都应该运行在此模式下,归档模式应该和 ...

  9. Extjs4 MVC Controlller中refs使用

    前面几篇写了一下mvc的整体使用方法,今天写一下controller中refs的试用,refs的作用类似于我们告诉controller我们的一个元素的别名,既alias,那么controller就会为 ...

  10. 8.1.C++ AMP简介

    C++ AMP是专为设计支持C++的异构并行模型. 全程是: Accelerator Massive Parallelism 下面是一个Vector C++ AMP的代码,通过这段代码来解释C++ A ...