Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

You will probably recognize the script below especially this command which was posted here over a year ago:

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

However, I am running into issues with it because it isn't recognizing PGP Corporation, all it sees is PGP I tried quotation marks but it didn’t help. Any Ideas?

@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
share|improve this question
1  
Who are you talking to? Who's "You"? :) You say you tried quotation marks, but that' shard to know what you mean exactly, can you provide the ACTUAL code you tried to use? –  Ƭᴇcʜιᴇ007 Dec 30 '13 at 20:56

1 Answer 1

Your folder has spaces in it, so you need to both wrap it in double-quotation marks (in both the for command and the do command), and specify that the for loop is not to use spaces as delimiters with the delims option:

for /f "delims=" %%i in ('dir /a:d /s /b "*PGP Corporation*"') do echo rd /s "%%i"
share|improve this answer
    
I suggest using "%%~i" instead of simply "%%~i", because some windows versions yield quoted value for the for variable, some don't. If yielded value will be quoted, "%%i" will produce double-double quotes, which may lead to side effects. %%~i is always unquoted. –  LogicDaemon Dec 30 '13 at 21:14
    
Good point. Yes, you should check that as well. In fact, this is why you should always preface your commands with an echo so that you can verify everything is correct before performing the actual changes because unexpected interactions like this can crop up sometimes. –  Synetech Dec 30 '13 at 21:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.