gpt4 book ai didi

c# - GetFiles 排除一个字符串

转载 作者:太空宇宙 更新时间:2023-11-03 22:42:53 26 4
gpt4 key购买 nike

使用下面的代码,我能够获取名称中包含 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com