遍历查找指定文件

private Regex nameRx = new Regex(@"([\w\W]*?).(doc|docx)",RegexOptions.IgnoreCase);
private void FildDoc(string path)
{
DirectoryInfo directory = new DirectoryInfo(path);
FileSystemInfo[] fileSystemInfos = directory.GetFileSystemInfos();
foreach (FileSystemInfo filess in fileSystemInfos)
{
if (fileSystemInfo is DirectoryInfo)
{
FildDoc( path);
}
else if (fileSystemInfo is FileInfo)
{
string fileName = fileInfo.Name;
if (nameRx.Match(fileName).Success)
{
//找到word文档了;
}
}
}
}

以查找word为例,中间有些异常没有处理的,使用时要加上。

你可能感兴趣的:(文件)