Windows CMD:在没有给定扩展名的情况下列出目录和子目录中的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4699146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows CMD: List files in dir & subdir WITHOUT given extensions
提问by DapperDan
I'd like to recursively search a directory and find files, which have NOT a certain extension, or precisely, which have NOT a certain set of extensions.
我想递归搜索目录并找到没有特定扩展名的文件,或者准确地说,没有特定的扩展名集。
Sketch: find in "dir" all files without "ext1", "ext2", "ext3" and print results to .txt
草图:在“目录”中查找所有没有“ext1”、“ext2”、“ext3”的文件并将结果打印到 .txt
I tried around several hours with DIR and ATTRIB, but unfortunately without bigger success.
我用 DIR 和 ATTRIB 尝试了几个小时,但不幸的是没有取得更大的成功。
Your consideration is highly regarded! Thanks.
您的考虑受到高度重视!谢谢。
回答by LittleBobbyTables - Au Revtheitroad
Try this:
尝试这个:
dir /b /s /a-d | findstr /vi ".ext1$ .ext2$ .ext3$"
The /a-d
switch excludes directories, giving you only files. The findstr
parameter lets you search the files for strings, and the /vi
switch indicates to exclude files containing the next parameter, the search being case insensitive.
该/a-d
开关不包括目录,让你只文件。该findstr
参数允许您在文件中搜索字符串,/vi
开关指示排除包含下一个参数的文件,搜索不区分大小写。
As Joey pointed out, the $
is necessary to indicate end of the line.
正如乔伊指出的那样,$
必须指示行的结尾。