获取指定文件夹及子文件夹中全部文件列表
/// <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