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

So this is what I have and it works great for one word folders e.g. c:\crap, but if I were to user "c:\my crap" all it will give me is c:\my I have tried quotations as seen below.

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

But there was no love an ideas would be awesome.

2 Answers 2


You need to set delims parameter. Something like this :

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

This produces this output on my system :

rd /s C:\stack\PGP Corporation\my crap

ps : in my case %%i does not work, i had to use %i


You need to put the directory path, in the rd statement, in quotes:

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

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.