list 列出文件夹但排除特定文件夹的批处理脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15568541/
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-11 01:59:00  来源:igfitidea点击:

Batch script to list folders but exclude specific folders

listbatch-filedirectorydir

提问by Tomas

I want this script to list all folders that contains "deleted" in the folder name but not if they is in a folder called "done".

我希望此脚本列出文件夹名称中包含“已删除”的所有文件夹,但如果它们位于名为“完成”的文件夹中,则不会列出。

For exampel: list the folder if it's in C:\tempand if it's in C:\temp\random_folder_namebut not not if it's in C:\temp\done

例如:列出文件夹,如果它在C:\temp,如果它在,C:\temp\random_folder_name但如果它在,则不列出C:\temp\done

dir /s "C:\temp" | findstr "\deleted"

short story, exclude all folders named "done" and their content.

短篇小说,排除所有名为“完成”的文件夹及其内容。

回答by Stephan

You are almost there.

你快到了。

Findstr /v returns all lines, that do not contain the string

Findstr /v 返回所有不包含字符串的行

dir /ad will only show directories (Atrribut=Directory)

dir /ad 将只显示目录(属性=目录)

dir /s /ad "C:\temp" | findstr "\deleted" | findstr /v "\done"

回答by Magoo

dir /s "C:\temp" | findstr "\deleted"|findstr /i /v "\temp\done\"

should fit the bill

应该符合要求

  • or remove the \temppart if you want to omit any name which has 'done' as a directory on the path
  • 或者\temp如果您想省略任何在路径上作为目录“完成”的名称,请删除该部分

回答by SuperTurbo

in lots of cases:

在很多情况下:

dir /b /s /aa <path>

Will do the trick. /b for less verbose output, /s for recursive (sub directories) and /aa for only files ready to be archived. This is usually the case for normal created files - it defaults to on!

会做的伎俩。/b 用于不太详细的输出,/s 用于递归(子目录)和 /aa 仅用于准备存档的文件。这通常是正常创建的文件的情况 - 默认为打开!