获取指定文件夹及子文件夹中全部文件列表
2017-05-26 12:50
246 查看
#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
相关文章推荐
- iOS小技巧 - 获取指定文件夹下的所有相对路径(包括子文件夹路径),并实现指定文件夹下的所有文件的全部移动
- 获取某某文件夹(包括子文件夹)下所有指定类型的文件
- WP7获取ISolatedStorage指定文件夹下所有子文件夹或者文件数
- 获取某某文件夹(包括子文件夹)下所有指定类型的文件
- 获取ftp服务器上指定文件夹的文件列表(包含文件大小)
- python 获取指定文件夹下所有文件名称并写入列表的实例
- python 获取指定文件夹下所有文件名称并写入列表
- 获取指定文件夹下文件列表
- symbian 获取指定路径下的文件夹和文件列表
- 从指定文件夹下获取文件路径列表的实现方法
- 获取指定文件夹下所有子目录及文件(树形)
- C#两种方式获取指定文件夹下所有子目录及文件
- 自动递归获取文件夹下面的文件列表
- 用递归获取文件夹以及子文件夹下的所有文件
- 获取指定文件夹下的所有文件+文件属性的获取与设置+文件夹属性的修改
- [ASP] 使用asp读取指定文件夹的文件列表(返回xml)
- 【转】获取指定文件夹下所有子目录及文件(树形)
- 获取服务器文件夹下文件列表
- 列出指定文件夹中的子文件夹和文件
- asp.net 获取指定文件夹下所有子目录及文件(树形)