Using the following batch script, I'm trying to remove old subdirectories. This snippet works perfectly when I use it in circumstances where there are no spaces in the directory names... However, when there are spaces in the directories, i have problems such as:
C:\Program Files\My Company Apps>rmdir /s /q "C:\Program Files\My Company Apps"\C:\Program
The filename, directory name, or volume label syntax is incorrect.
Here is the batch code I'm tinkering with....
IF EXIST "C:\Program Files\My Company Apps" (
SET App32dir=C:\Program Files\My Company Apps
dir /b /ad "%App32dir%" > "%App32dir%\dirlist.txt"
for /f %%i in ("%App32dir%\dirlist.txt") do rmdir /s /q "%App32dir%"\%%i
) ELSE (
ECHO : My Company Apps Not Found
I have tried every combination I can think of..
"%App32dir%\%%i" and "%App32dir%"\"%%i"
I have also tried only using quotes in the SET command, then removing them from the variable %App32dir% but still to no avail....
The dirlist.txt populates correctly with the subdirectories names...
All have spaces, like:
My First App
My Second App
My Third App
My Fourth App
And So On
So, the dirlist.txt file looks good, but since the directories have spaces, the rmdir command doesn't work..