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. hdu4638Group

    http://acm.hdu.edu.cn/showproblem.php?pid=4638 求某一区间所包含的连续的段 对于乱序的数 到了i这个数所包含的段数 首先把这个数看作单独的段 再看一下前面 ...

  2. sh脚本执行Java程序

    1.不引用Jar包或者资源文件夹 最简单的程序Hello World. 首先创建Hello.java public class Hello { public static void main(Stri ...

  3. Java [Leetcode 43]Multiply Strings

    题目描述: Given two numbers represented as strings, return multiplication of the numbers as a string. No ...

  4. Java [leetcode 35]Search Insert Position

    题目描述: Given a sorted array and a target value, return the index if the target is found. If not, retu ...

  5. SharePoint 2010 master page 控件介绍(5):其他

    转:http://blog.csdn.net/lgm97/article/details/6409227 <!-- 处理搜索按下"enter"键和点击后退按钮 --> ...

  6. Application Pool Identities

    Whether you are running your site on your own server or in the cloud, security must be at the top of ...

  7. NOIP2012 Vigenère 密码

    1.Vigenère 密码 (vigenere.cpp/c/pas) [问题描述] 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法——Vigenère 密码.V ...

  8. adb 启动失败的原因和修改adb端口号

    在我们使用Android Studio的时候,有时候就会出现adb打开失败或者启动不了的情况. adb 启动失败的原因:有其他程序占用了adb默认启动的端口号(像我就遇到过,每次只要提前启动了酷狗音乐 ...

  9. ffmpeg 的tutorial

    可能是新的: https://github.com/chelyaev/ffmpeg-tutorial https://github.com/chelyaev/ffmpeg-tutorial.git 老 ...

  10. TreeView节点

    TreeView由节点构成,建树通过对TreeView.items属性进行操作.Items是一个TTreeNodes对象,这是一个TTreeNode集. 一.针对TTreeNodes,也就是 Tree ...