General discussion

Locked

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

By dbrunt1 ·
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 conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

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

by dbrunt1 In reply to DOS - How to delete all f ...

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.

Back to Networks Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums