DOS - How to delete all files and subdirectories in a dir but not the dir - TechRepublic
General discussion
March 1, 2017 at 10:44 PM
dbrunt1

DOS – How to delete all files and subdirectories in a dir but not the dir

by dbrunt1 . Updated 9 years, 3 months ago

DOS – How to delete all files and subdirectories in a directory.

By CharlieSpencer · 9 years ago

Okay, not really DOS, but from a Windows Server command prompt.

I’m trying to remember how to delete all files, subdirectories, and subdirectory contents from a specific directory from a command prompt. We have a “catch all” folder for short-term file sharing and I want to delete the contents nightly, but not the folder itself, using a scheduled command procedure.

Unfortunately I’m the poster boy for the American CRS Foundation and have forgotten how to do this. RMDIR won’t take a wildcard. DELTREE is apparently dead and gone. I’m currently using

DEL /F /Q /S C:\Directory\*.*

but that leaves the empty subdirs in place.

Help. Thanks.

This discussion is locked

All Comments