liango
liango

Reputation: 804

how to delete folders but not files in a folder by cmd

How to delete folders but not files in a folder by cmd?

Such as, there is a direcory:

c:\image\1.png
c:\image\2.png
c:\image\3.png
c:\image\*.png
c:\image\folder1\*.png
c:\image\folder2\*.png
....

Now I don't know how to delete all the folders (and subfiles) folder1, folder2...", only remain the files 1.png, 2.png, 3.png, 4.png ...

Upvotes: 1

Views: 2524

Answers (1)

dbenham
dbenham

Reputation: 130819

for /d %F in (c:\image\*) do rd /s /q "%F"

Double up the percents if used within a batch file

Upvotes: 4

Related Questions