Directory.GetFiles 方法
Directory.GetFiles 方法
返回指定目录中文件的名称(包括其路径)。
命名空间: System.IO
程序集: mscorlib(mscorlib.dll 中)
EnumerateFiles和GetFiles方法的行为有所不同,如下所示: 当您使用EnumerateFiles,您可以开始之前,则返回整个集合 ; 枚举名称的集合当您使用GetFiles,您必须等待的名称,然后才能访问该数组要返回整个数组。因此,当您正在使用多个文件和目录、EnumerateFiles效率更高。
返回的文件名将追加到提供path参数。
此方法等同于GetFiles(String, String)用星号 (*) 指定为搜索模式。
path参数可以指定相对或绝对路径信息。相对路径信息被解释为相对于当前的工作目录。若要获取当前工作目录,请参阅GetCurrentDirectory。
不能保证返回的文件名称的顺序 ;使用Sort方法是否需要特定的排序顺序。
path参数不区分大小写。
通用 I/O 任务的列表,请参阅通用 I/O 任务。
string[] files = Directory.GetFiles(this.TargetPath, this.TargetName + "*.sql");
if (files == null || files.Length <= )
{
throw new Exception("还原数据库是获取源文件失败");
}

Directory.GetFiles获取多个类型的文件
var files = Directory.GetFiles("C:\\path", "*.*", SearchOption.AllDirectories)
.Where(s => s.EndsWith(".mp3") || s.EndsWith(".jpg"));
Directory.GetFiles 方法的更多相关文章
- Directory的GetFiles方法
想实现一个功能 :比如多个业务审批流程公用一个审批表的时候,有一个提示审批信息的页面 ,点击该页面不同的业务审批流程记录的时候,跳转到不同业务流程的详细显示界面 额 这样说 貌似以后我自己也看不明白 ...
- C# Directory.GetFiles()获取文件时如果是根目录时有隐藏文件则报错的处理
如果Directory.GetFiles("d:\"),则由于回收站是隐藏文件而报错,怎么躲避这种错误呢, 我要了一种办法,只要遇到隐藏文件夹就跳过的方法: foreach (va ...
- C#中Directory.GetFiles() 函数的使用
C#中Directory.GetFiles(string path , string searchPattern, SearchOption searchOption ) 获取path目录中所有文件 ...
- 在.NET Framework中慎用DirectoryInfo.GetFiles方法
.NET Framework中的DirectoryInfo.GetFiles方法,可以在一个文件夹下通过通配符找出符合条件的文件. 我们首先在文件夹C:\DemoFolder下定义两个文件:demo. ...
- Ubuntu下 fatal error: Python.h: No such file or directory 解决方法
参考: fatal error: Python.h: No such file or directory Ubuntu下 fatal error: Python.h: No such file or ...
- numa.h:No such file or directory 解决方法
参考: numa.h:No such file or directory numa.h:No such file or directory 解决方法 Ubuntu: $ apt-get install ...
- 在c#中过滤通过System.IO.Directory.GetDirectories 方法获取的是所有的子目录和文件中的系统隐藏的文件(夹)的方法
//读取目录 下的所有非隐藏文件夹或文件 public List<FileItem> GetList(string path) { int i; string[] folders = Di ...
- C# Directory.GetFiles()获取多个类型格式的文件
第一种方式 System.IO.Directory.GetFiles()获取多个类型格式的文件 System.IO.Directory.GetFiles("c:\","( ...
- vsftpd出现“Response: 500 OOPS: cannot change directory”解决方法(转载)
vsftpd出现“Response: 500 OOPS: cannot change directory”解决方法 笔者用的Linux发行版本为centos当用FTP客户端连接时,出现如下错误提示 ...
随机推荐
- AJAX快速上手
创建XMLHttpRequest对象 xmlHttp = new XMLHttpRequest(); xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); ...
- 可选头 IMAGE_OPTIONAL_HEADER
//IMAGE_OPTIONAL_HEADER结构(可选映像头) typedef struct _IMAGE_OPTIONAL_HEADER { // // Standard fields. // W ...
- CSS5.4 安装问题集
由于手痒,将5.2 卸载了,装了5.4 出现如下错误:install failed to install com.ti.ccstudio.debugserver.win32 corrctly. ... ...
- 从win7到mac os再到win10,体验总结
首先介绍自己的身份,软件工程毕业,现在IT男一枚,php程序员(前端必须会的啦). 原先自己用的是win7系统,大学四年都在用,所以习惯了.开发方式也是传统式的,以文件概念为主(就是手动管理文件),版 ...
- jquery-qrcode在线生成二维码
通过bower进行获取: y@y:ydkt$ bower install jquery-qrcode --save bower not-cached git://github.com/gcusnieu ...
- window.onscroll
http://www.w3help.org/zh-cn/causes/SD9013 1.各浏览器对 document.document.body.document.documentElement 对象 ...
- Check if a string is NULL or EMPTY using PowerShell
http://techibee.com/powershell/check-if-a-string-is-null-or-empty-using-powershell/1889 Check if a s ...
- [LeetCode] 35. Search Insert Position 解决思路
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- 程序设计实习MOOC / 继承和派生——编程作业 第五周程序填空题1
描述 写一个MyString 类,使得下面程序的输出结果是: 1. abcd-efgh-abcd- 2. abcd- 3. 4. abcd-efgh- 5. efgh- 6. c 7. abcd- 8 ...
- SQL-Duplicate Emails
思路: 两种思路,可以给当成两个表也可以给当成一张表来做 group by就是按照某个属性给表分个组,然后having语句的含义是“对于每一个group”怎么怎么样 补充知识:count(column ...