使用批处理文件删除文件夹

使用批处理文件删除文件夹

您可能会认出下面的脚本,特别是这个一年前在这里发布的命令:

for /f %%i in ('dir /a:d /s /b *PGP Corporation*') do echo rd /s %%i

但是,我遇到了问题,因为它无法识别PGP Corporation,它看到的只是PGP我尝试了引号,但没有帮助。有什么想法吗?

@echo off
cls
echo searching for pgp corp folders
cd c:\users
for /f %%i in ('dir /a:d /s /b *PGP Corporation*') do echo rd /s %%i
echo are these the folders you want to delete? 
choice /t 15 /d n /M "Do you want to delete these folders type y for yes"
if errorlevel 2 goto no
if errorlevel 1 goto yes
goto end

:no
echo you slelected no
pause
goto end

:yes
echo you selected yes and the folders will be deleted
for /f %%i in ('dir /a:d /s /b *PGP Corporation*') do rd /s /q %%i

choice /t 15 /d n /m "Do you want to try and install PGP 10.3 now?
if errorlevel 2 goto noo
if errorlevel 1 goto yess

:noo
echo you selected not to instal. Goodbye.
goto end

:yess
echo Installation of PGP will begin Momentarily
"\\dts\apps\PGP\PGP Latest\pgp 103 64bit.msi"

pause

答案1

您的文件夹中有空格,因此您需要将其用双引号引起来(在命令fordo命令中),并使用以下选项指定for循环不使用空格作为分隔符delims

for /f "delims=" %%i in ('dir /a:d /s /b "*PGP Corporation*"') do echo rd /s "%%i"

相关内容