Discussion Locked

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

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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.

1 reply

by dbrunt1

Charles,
Here is your answer:

cd C:\Directory
rd . /q /s

Because you are in C:\Directory, it will fail to remove that folder but everything else will be deleted.

This discussion is closed to new replies.