簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM