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. 1439. Battle with You-Know-Who(splay树)

    1439 路漫漫其修远兮~ 手抄一枚splay树 长长的模版.. 关于spaly树的讲解   网上很多随手贴一篇 貌似这题可以用什么bst啦 堆啦 平衡树啦 等等 这些本质都是有共同点的 查找.删除特 ...

  2. poj 2240 Arbitrage (最短路 bellman_ford)

    题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...

  3. 百度地图API的调用

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  4. Erlang入门(四)——错误处理和鲁棒性

    去了趟福州,事情没搞定,托给同学帮忙处理了,回家休息了两天就来上班了.回家这几天最大的收获是第四次重读<深入Java虚拟机>,以前不大明了的章节豁然开朗,有种开窍的感觉,水到渠成,看来技术 ...

  5. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.5

    Show that the inner product $$\bex \sef{x_1\vee \cdots \vee x_k,y_1\vee \cdots\vee y_k} \eex$$ is eq ...

  6. java中的快捷键

    Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当 ...

  7. HDU2015校赛 The Country List

    今天手感真差..各种读错题意.水题... 就是说,给你几个串.如果长度一样并且相同位置字符相同(不分大小写)的个数大于两个就是不同串. #include<iostream> #includ ...

  8. 2014上海网络赛 HDU 5053 the Sum of Cube

    水 #include <stdio.h> #include <stdlib.h> #include<math.h> #include<iostream> ...

  9. 部分常用Express方法详解

    app.set(name, value) 分配给name一个value,并将name作为app settings table的一个属性. 使用app.set('foo', true) 相当于调用 ap ...

  10. HW6.29

    public class Solution { public static void main(String[] args) { int count = 0; int[] card = new int ...