GetFiles 排除一个字符串
GetFiles exclude a string
使用以下代码,我能够获取名称中包含 string
的所有文件:
DirectoryInfo dirInf = new DirectoryInfo(path);
FileInfo[] fInfArray = dirInf.GetFiles("*string*");
但是 如何排除 GetFiles
处的字符串。
我不是说像 .txt
这样的结尾,我想在文件名中排除 string
。
例如我有以下文件:
wordwordfile.msg
wordwordfile.txt
wodfile.txt
并排除 wod 以获取以下文件:
wordwordfile.msg
wordwordfile.txt
var files = new DirectoryInfo("C:\")
.EnumerateFiles("*string*")
.Where(f => !f.Name.Contains("wod"))
// Optional, convert to array if you want
.ToArray();
使用以下代码,我能够获取名称中包含 string
的所有文件:
DirectoryInfo dirInf = new DirectoryInfo(path);
FileInfo[] fInfArray = dirInf.GetFiles("*string*");
但是 如何排除 GetFiles
处的字符串。
我不是说像 .txt
这样的结尾,我想在文件名中排除 string
。
例如我有以下文件:
wordwordfile.msg
wordwordfile.txt
wodfile.txt
并排除 wod 以获取以下文件:
wordwordfile.msg
wordwordfile.txt
var files = new DirectoryInfo("C:\")
.EnumerateFiles("*string*")
.Where(f => !f.Name.Contains("wod"))
// Optional, convert to array if you want
.ToArray();