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. Codeforces 374B - Inna and Nine

    原题地址:http://codeforces.com/problemset/problem/374/B 这道题没什么难度,但是考场上就是没写对.Round #220彰显了它的逗比性质——这道题的“标算 ...

  2. bzoj1058: [ZJOI2007]报表统计

    set.操作:insert(u,v)在u后面插入v,若u后面已插入过,在插入过的后面插入.mingap求出序列两两之间差值的最小值.minsortgap求出排序后的序列两两之间的最小值.用multis ...

  3. JS框架整理

    1. Dojo (演示地址) Dojo是一个强大的面向对象JavaScript框架.主要由三大模块组成:Core.Dijit.DojoX.Core提供ajax,events,packaging,CSS ...

  4. acdream 小晴天老师系列——苹果大丰收(DP)

    小晴天老师系列——苹果大丰收 Problem Description 小晴天的后花园有好多好多的苹果树,某天,苹果大丰收~小晴天总共摘了M个苹果,我们假设苹果之间是不可分辨的. 为了保存苹果,小晴天买 ...

  5. 如何在Azure Websites中配置PHP从而改变系统默认时区

    Shirley_Wang  Tue, Mar 3 2015 7:29 AM Azure Website为我们提供了可高度扩展的网站部署平台.由于Website是PaaS(平台即服务)层的服务,当用户把 ...

  6. (1)java虚拟机概念和结构图

    java虚拟机解构图一 java虚拟机解构图二 java虚拟机结构图三 [1]类加载系统        --->负责从文件系统或网络中加载class信息,存放至方法区的内存空间[2]java堆  ...

  7. (二)学习MVC之实现用户注册功能

    学习地址:http://www.cnblogs.com/mzwhj/archive/2012/10/22/2720089.html 本文和学习地址不一样的地方是我自己添加了一些简单的注释和理解. 1. ...

  8. MySQL性能指标及计算方法

    绝大多数MySQL性能指标可以通过以下两种方式获取: (1)mysqladmin 使用mysqladmin extended-status命令获得的MySQL的性能指标,默认为累计值.如果想了解当前状 ...

  9. HDU 4393 Throw nails

    Throw nails Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. 【转】修改xampp的mysql默认密码

    http://www.cnblogs.com/hongchenok/archive/2012/08/21/2648549.html MySQL 的“root”用户默认状态是没有密码的,所以在 PHP ...