I am doing the same as described here i.e. In my batch file, I am using rmdir E:\docs\music /S /Q
to delete all the content including sub directories too but it is removing parent directory music
also which I don't want.
Do I need to run mkdir
everytime?
Asked
Active
Viewed 1,799 times
2
-
Have you tried using wildcards? – Bob. Oct 15 '12 at 19:10
-
`rmdir E:\docs\music\* /S /Q` is showing `The filename, directory name, or volume label syntax is incorrect.` – ravi Oct 15 '12 at 19:11
2 Answers
3
If you cd
into E:\docs\music
then execute rmdir E:\docs\music /S /Q
everything will be deleted under music
but not the music
directory itself.

Chimera
- 5,884
- 7
- 49
- 81
2
Single line solution uses for
to produce a list of the inner directories :
for /f %i in ('dir /ad /b music') do @rmdir /s /q music\%i
You must escape the %
if you put that line in a batch file, like this :
for /f %%i in ('dir /ad /b music') do @rmdir /s /q music\%%i

ixe013
- 9,559
- 3
- 46
- 77