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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:59:04  来源:igfitidea点击:

Windows CMD: List files in dir & subdir WITHOUT given extensions

windowsfilelistshellcommand-line

提问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-dswitch excludes directories, giving you only files. The findstrparameter lets you search the files for strings, and the /viswitch 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.

正如乔伊指出的那样,$必须指示行的结尾。