简体   繁体   English

从特定目录获取除特定扩展名以外的所有文件

[英]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.

相关问题 使用Directory.GetFiles()选择除特定扩展名之外的所有文件 - Using Directory.GetFiles() to select all the files but a certain extension 如何获取 C# 中具有特定扩展名的目录中的所有文件? - How to get all files in a directory with certain extension in C#? 从目录获取基于创建日期的文件时,获取特定文件扩展名 - Get a certain file extension while getting files based on creation date from a directory 在特定目录中获取所有名称空间 - Getting all namespaces in certain directory 获取特定目录中音频文件的所有文件路径的列表 - Getting a List of all filepaths for Audio Files in a certain directory 从目录中获取文件时排除某些文件扩展名 - Exclude certain file extensions when getting files from a directory 如何获得具有特定扩展名的目录中的所有文件,其格式允许我在下拉列表或广播列表中使用它? - How do I get all files in a directory with a certain extension in a format that allows me to use it in a dropdown or radiolist? 从目录中排除某些文件 - Exclude certain files from compiling in directory 某些扩展名的 Directory.GetFiles - Directory.GetFiles of certain extension 去除除某些 HTML 标签之外的所有 HTML 标签? - Strip all HTML tags except certain ones?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM