使用下面的代码,我能够获取名称中包含 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();
关于c# - GetFiles 排除一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51400222/