获取指定目录及子目录中所有文件列表
2015-08-21 12:04
399 查看
#region 获取指定目录及子目录中所有文件列表
/// <summary>
/// 获取指定目录及子目录中所有文件列表
/// </summary>
/// <param name="directoryPath">指定目录的绝对路径</param>
/// <param name="searchPattern">模式字符串,"*"代表0或N个字符,"?"代表1个字符。
/// 范例:"Log*.xml"表示搜索所有以Log开头的Xml文件。</param>
/// <param name="isSearchChild">是否搜索子目录</param>
public static string[] GetFileNames(string directoryPath, string searchPattern, bool isSearchChild)
{
//如果目录不存在,则抛出异常
if (!IsExistDirectory(directoryPath))
{
throw new FileNotFoundException();
}
try
{
if (isSearchChild)
{
return Directory.GetFiles(directoryPath, searchPattern, SearchOption.AllDirectories);
}
else
{
return Directory.GetFiles(directoryPath, searchPattern, SearchOption.TopDirectoryOnly);
}
}
catch (IOException ex)
{
throw ex;
}
}
#endregion
/// <summary>
/// 获取指定目录及子目录中所有文件列表
/// </summary>
/// <param name="directoryPath">指定目录的绝对路径</param>
/// <param name="searchPattern">模式字符串,"*"代表0或N个字符,"?"代表1个字符。
/// 范例:"Log*.xml"表示搜索所有以Log开头的Xml文件。</param>
/// <param name="isSearchChild">是否搜索子目录</param>
public static string[] GetFileNames(string directoryPath, string searchPattern, bool isSearchChild)
{
//如果目录不存在,则抛出异常
if (!IsExistDirectory(directoryPath))
{
throw new FileNotFoundException();
}
try
{
if (isSearchChild)
{
return Directory.GetFiles(directoryPath, searchPattern, SearchOption.AllDirectories);
}
else
{
return Directory.GetFiles(directoryPath, searchPattern, SearchOption.TopDirectoryOnly);
}
}
catch (IOException ex)
{
throw ex;
}
}
#endregion
相关文章推荐
- Eclipse常规设置(我的Style我做主)
- UITextfield后面只能输入小数点后2位
- Android事件传递机制
- 从AFX_MANAGE_STATE(AfxGetStaticModuleState())说起
- ProgressBar通过动画定义实现
- SVM常用的核函数
- 【模拟+数据结构】UVA 11995 I Can Guess the Data Structure!
- 看论坛一个帖子带来的震撼--熟悉函数多么重要(glob函数)
- C++中的case标签
- mysql linux 5.6 去掉 STRICT_TRANS_TABLES
- adaBoost算法
- IOS UIPageControl(分页控制器) 用法总结
- Android设置透明效果
- nginx限制用户下载文件速率
- mvc项目中发送邮件
- linux查找关键字在php出现的次数
- SpringMVC 使用poi导入导出Excel
- 文档如何进行双面打印
- HTML5游戏 围住神经猫 开发
- xjc命令转换成java类乱码