简体   繁体   English

使用批处理命令忽略dir命令后的特定文件?

[英]Batch command to ignore specific files after dir command?

How do I set a batch script to ignore certain files? 如何设置批处理脚本以忽略某些文件? Like, not filter, but exact files. 喜欢,不是过滤器,而是确切的文件。 Like 喜欢

dir /b *.zip

Results in the file list 文件列表中的结果

file1.zip
file2.zip
file3.zip
file4.zip
file5.zip

And I want to ignore the specific files 我想忽略特定的文件

file3.zip
file4.zip

And end up with the file list result 并最终得到文件列表结果

file1.zip
file2.zip
file5.zip

How do I do this? 我该怎么做呢?

dir /b *.zip|findstr /v /i /g:"filecontainingexcludednamesonetoaline.txt"

should handle this task quite adequately. 应该足够充分地完成这项任务。


On more information provided (best to provide relevant information at the start to prevent an endless revision cycle) 关于提供的更多信息(最好在开始时提供相关信息,以防止无休止的修订周期)

...
dir /b *.zip|findstr /x /v /i /g:"~f0"
....
goto :eof
---- this info at end-of-file. just plain text
---- files-to-exclude-from-listing
---- these last 3 lines are just comments playing no part in the script
exclude me.zip
and_me.zip
dont_show me.zip

Nearly the same as Magoo's answer, but without the extra file, and also with the addition of the /L option to force a literal match: 与Magoo的答案几乎相同,但是没有多余的文件,并且还添加了/ L选项以强制文字匹配:

dir /b *.zip|findstr /vilx /c:"file1.zip" /c:"file2.zip"

This is a bit overkill for this problem, but you could also use my JREN.BAT utility . 对于这个问题,这有点矫kill过正 ,但是您也可以使用我的JREN.BAT实用程序 It is primarily intended for renaming files, but it does have an option to list files instead. 它主要用于重命名文件,但确实可以选择列出文件。 The advantage of this utility is it allows you to specify very precise regular expression terms to match, as well as to specify files to exclude. 该实用程序的优点是它允许您指定要匹配的非常精确的正则表达式术语,并指定要排除的文件。

In this case, I use the /FM and /FX options to specify masks with normal Windows wildcard rules instead of using regular expressions. 在这种情况下,我使用/ FM和/ FX选项使用常规Windows通配符规则指定掩码,而不使用正则表达式。

jrepl "^" "" /list /fm *.zip /fx "file1.zip|file2.zip"

If you have complicated matching rules, then /RFM and /RFX could be used to specify regular expression masks instead. 如果您有复杂的匹配规则,则可以使用/ RFM和/ RFX来指定正则表达式掩码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM