[英]Getting all files from a certain directory except a certain extension
I would like to get all the files from a directory except the files that have a certain extension. 我想从目录中获取除具有特定扩展名的文件之外的所有文件。
In my directory I have the following files: 在我的目录中,我有以下文件:
file1.txt
file1.ok
file2.txt
file2.ok
file3.txt
file3.ok
file4.txt
file5.xml
file6.ok
I can get the "ok"-files by using Directory.GetFiles(sourceDirectory, "*.ok") But how can i get a list of all the other files? 我可以通过使用Directory.GetFiles(sourceDirectory,“* .ok”)获得“ok”文件但是如何获得所有其他文件的列表? A list of all the files that do not have the extions ".ok".
没有extions“.ok”的所有文件的列表。
You can use a simple Where
for this: 您可以使用简单的
Where
:
Directory.GetFiles(sourceDirectory)
.Where(x => Path.GetExtension(x) != ".ok");
尝试这个
Directory.GetFiles("path").Where(x=> Path.GetExtension(x)!=".extension");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.