I am trying to get a batch file to delete folders and their contents. The batch file deletes all the files contained in the folders, BUT the folders still remain.
del /s /f /q C:\Users\GT\AppData\Roaming\uTorrent\CompletedDL\*.*
for /f %%f in ('dir /ad /b C:\Users\GT\AppData\Roaming\uTorrent\CompletedDL\') do rd /s /q
C:\Users\GT\AppData\Roaming\uTorrent\CompletedDL\%%fcan anyone see what the problem is?
31 Answer
I don't know what's not working in your script, but this should work:
del /f /q "%appdata%\uTorrent\CompletedDL\*.*"
for /d %%d in ("%appdata%\uTorrent\CompletedDL\*.*") do rmdir /s /q "%%d"The /d switch searches for subdirectories which are then removed with rmdir. I also added double quotes, because rmdir would break if the path contains spaces.
The /s switch in the del command is not neccesary, because rmdir /s will remove files as well.