[英]Batch command to ignore specific files after dir command?
如何设置批处理脚本以忽略某些文件? 喜欢,不是过滤器,而是确切的文件。 喜欢
dir /b *.zip
文件列表中的结果
file1.zip
file2.zip
file3.zip
file4.zip
file5.zip
我想忽略特定的文件
file3.zip
file4.zip
并最终得到文件列表结果
file1.zip
file2.zip
file5.zip
我该怎么做呢?
dir /b *.zip|findstr /v /i /g:"filecontainingexcludednamesonetoaline.txt"
应该足够充分地完成这项任务。
关于提供的更多信息(最好在开始时提供相关信息,以防止无休止的修订周期)
...
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
与Magoo的答案几乎相同,但是没有多余的文件,并且还添加了/ L选项以强制文字匹配:
dir /b *.zip|findstr /vilx /c:"file1.zip" /c:"file2.zip"
对于这个问题,这有点矫kill过正 ,但是您也可以使用我的JREN.BAT实用程序 。 它主要用于重命名文件,但确实可以选择列出文件。 该实用程序的优点是它允许您指定要匹配的非常精确的正则表达式术语,并指定要排除的文件。
在这种情况下,我使用/ FM和/ FX选项使用常规Windows通配符规则指定掩码,而不使用正则表达式。
jrepl "^" "" /list /fm *.zip /fx "file1.zip|file2.zip"
如果您有复杂的匹配规则,则可以使用/ RFM和/ RFX来指定正则表达式掩码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.