Delete Files/Subfolder but keep parent

Associate
Joined
4 Jun 2007
Posts
2,282
Location
South Wales
Hey guys,

Looking for a way to delete all subfolder and files but keep the parent directory within cmd or if push comes to shove powershell (would prefer cmd so I can make a bat file)

i.e.
C:\Parent\Sub1\*.*
C:\Parent\Sub1\*.*
C:\Parent\Sub2\*.*
C:\Parent\Sub2\Sub3\*.*

Basically I want to keep C:\Parent but delete all of its contents, closest I can find would be RMDIR /S but that would delete C:\Parent as well or using cd C:\Parent which seems like a long winded way to do it, especially if I then want to add C:\Parent2 etc to it
 
If you use DEL C:\parent\*.* doesn't that only delete everything within parent but not parent itself?

Ah - doesn't delete the subfolder as standard, I thought I'd remembered that it did.
 
Last edited:
Yeah, I was just about to suggest the /s parameter. Except in my quick check that deleted all files from subfolders too - but still didn't delete the subfolder structure.
 
Back
Top Bottom