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
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

echo you slelected no
goto end

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

echo you selected not to instal. Goodbye.
goto end

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

  • 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? Dec 30, 2013 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"
  • 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. Dec 30, 2013 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, 2013 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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