
我有一個命令列腳本,可以刪除文字檔案中未列出的所有資料夾名稱。我希望腳本僅刪除文字檔案中的資料夾。我不確定出了什麼問題。
我的命令是:
for /d %%a in ("C:\Users\Administrator\Desktop\Somedir\*") do findstr /i /x /c:"%%~nxa" Cleanup.txt || rd /s /q %%a
我的文字檔案包含短資料夾名稱,例如:
am
ar
bg
有人可以幫忙嗎?
答案1
在命令列中:
cd "C:\Where\Your\Text\File\Is"
for /f %A in ("Cleanup.txt") do (if exist "C:\Users\Administrator\Desktop\Somedir\%A" rd /s /q "C:\Users\Administrator\Desktop\Somedir\%A")
批量:
@echo off
set "dir=C:\Users\Administrator\Desktop\Somedir"
set "txt=C:\Where\Your\File\Is\Located\Cleanup.txt"
setlocal enabledelayedexpansion
for /f %%A in (%txt%) do (
set "del=%%A"
if exist "%dir%\!del!" rd /s /q "%dir%\!del!"
)
如果您不想為循環選項添加任何其他內容,請記住在命令列中更改目錄。我更喜歡使用批次和變量,所以我將其包括在內。