I'm trying to delete all directories based off a naming convention using a batch file in windows. I don't want to delete all directories, only one's that match a pattern.
I'm doing this on Windows Server, so I don't know if that matters. I can get this to work on my personal desktop, but when I attempt on the Windows Server computer it doesn't work.
Echo Deleting Folders
cd C:\Users\srvFIPITSTOPPAPP1\AppData\Roaming\Enfocus\Switch Server\temp
pause
For /D /r %%i in ("*mail*") DO rd /Q /S %%i
pause
echo Done
When this is run, it iterates through all the directories and lists them. But then after it lists them all it says the following:
"The system cannot find the file specified."
"The system cannot find the path specified."
I find this odd since it literally lists every path and then says it can't find it. I'm sure I'm missing something small. Any help is appreciated.
Solved:
Echo Deleting Folders
cd C:\Users\srvFIPITSTOPPAPP1\AppData\Roaming\Enfocus\Switch Server\temp
pause
for /F "delims=" %%I in ('dir /S /B /A:D "*mail*" ^| sort /R') do @rd /S /Q "%%I"
pause
echo Done