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? A list of all the files that do not have the extions ".ok".
You can use a simple Where
for this:
Directory.GetFiles(sourceDirectory)
.Where(x => Path.GetExtension(x) != ".ok");
尝试这个
Directory.GetFiles("path").Where(x=> Path.GetExtension(x)!=".extension");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.