は、スクリプトの各部分を記述するためにコメントし、このための別の解決策です:
@Echo OFF
REM Important that Delayed Expansion is Enabled
setlocal enabledelayedexpansion
REM This sets what folder the batch is looking for and the root in which it starts the search:
set /p foldername=Please enter the foldername you want to delete:
set /p root=Please enter the root directory (ex: C:\TestFolder)
REM Checks each directory in the given root
FOR /R %root% %%A IN (.) DO (
if '%%A'=='' goto end
REM Correctly parses info for executing the loop and RM functions
set dir="%%A"
set dir=!dir:.=!
set directory=%%A
set directory=!directory::=!
set directory=!directory:\=;!
REM Checks each directory
for /f "tokens=* delims=;" %%P in ("!directory!") do call :loop %%P
)
REM After each directory is checked the batch will allow you to see folders deleted.
:end
pause
endlocal
exit
REM This loop checks each folder inside the directory for the specified folder name. This allows you to check multiple nested directories.
:loop
if '%1'=='' goto endloop
if '%1'=='%foldername%' (
rd /S /Q !dir!
echo !dir! was deleted.
)
SHIFT
goto :loop
:endloop
あなたが最初の変数の前にあるから/p
を取ると、ちょうどあなたドン場合=
後にその値を入力することができます「Tは、プロンプトが表示されるようにしたい:
set foldername=
set root=
あなたはまた、サイレントバッチのループ部分と端部でpause
にecho
を削除することができます。
もう少し複雑かもしれませんが、コードは他の多くの用途にも適用できます。
私はC:\Test
に同じフォルダ名qwerty
の複数のインスタンスを探して、それをテストした:
C:\Test\qwerty
C:\Test\qwerty\subfolder
C:\Test\test\qwerty
C:\Test\test\test\qwerty
放置したことのすべてだった:
C:\Test\
C:\Test\test\
C:\Test\test\test\
あなたはそれがまったく同じものに少し説明することができますか? fileprefixとは何ですか?そしてそれらの旗。今それを試してください。 – Achshar
このリンクがお役に立てば幸いです。 http://www.robvanderwoude.com/batchcommands.php – StarPinkER
@Achshar:基本的に、 'fileprefix'(' ... IN(Y *)DO ... ')ではなくYフォルダの名前を入れてください。また、Xフォルダのパスを '/ R'と' %% X'の間に置いてください(Jermaineは '/ R'スイッチが引数を必要とすることを忘れてしまいました。もう一つは、条件を追加して 'Y'フォルダを削除し、' Y * 'マスクにも一致する' Ysomething 'を削除する必要があります。このようなことが起こるかもしれません: '... DO IF" %%〜nxX "==" Y "RD ...'。 –