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. 用shell写个100以内的所有数字之和

    #!/bin/bash i=2 while ((i<=100));do j=2 while ((j<=i/2));do if ((i%j==0));then break fi let j+ ...

  2. UVa 1151 (枚举 + MST) Buy or Build

    题意: 平面上有n个点,现在要把它们全部连通起来.现在有q个套餐,如果购买了第i个套餐,则这个套餐中的点全部连通起来.也可以自己单独地建一条边,费用为两点欧几里得距离的平方.求使所有点连通的最小费用. ...

  3. 20款最优秀的JavaScript编辑器

    毫无疑问SublimeText,Notepad++,webstorm等,是市面上最主导的编辑器,但当然也有一些更多的JavaScript编辑器提供众多的特性和功能,方便和轻松自由的编码.本文整理了20 ...

  4. 【转】Android开发20——单个监听器监听多个按钮点击事件

    原文网址:http://woshixy.blog.51cto.com/5637578/1093936 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律 ...

  5. 【转】【iOS】导航栏那些事儿

    原文网址:http://www.jianshu.com/p/f797793d683f 参考文章 navigationItem UINavigationItem UINavigationBar UIBa ...

  6. Spring入门之HelloSpring

    Spring描述: -轻量级:Spring是非侵入式的-基于Spring开发的应用中的对象可以不依赖于Spring的API -依赖注入(DI---dependency injection,IOC) - ...

  7. JavaScript基础大全篇

    本章内容: 简介 定义 注释 引入文件 变量 运算符 算术运算符 比较运算符 逻辑运算符 数据类型 数字 字符串 布尔类型 数组 Math 语句 条件语句(if.switch) 循环语句(for.fo ...

  8. UVA 10462 Is There A Second Way Left? 次小生成树

    模板题 #include <iostream> #include <algorithm> #include <cstdio> #include <cstdli ...

  9. 理解public,protected 以及 private

    经常看到在类中看到public,protected,private以及它们在继承中表示的一些访问范围,很容易搞糊涂.我们首先要明白下面几点. 1.类的一个特征就是封装,public和private作用 ...

  10. C#递归遍历指定目录下文件和文件夹

    #region 使用递归查询某路径中的文件结构 public static void CheckFilePath() { ReadFilePath(); } public static void Re ...