Windows command for deleteing files/directories

Associate
Joined
27 Jun 2008
Posts
1,538
Is there a command in windows that will delete all the directories and files withing a directory but not the root directory?

ie C:\files\today\ {contains various files/folders that could be named as anything that need deleting, essentially a temp folder}

CD is C:\

Using RMDIR /S /Q files\today\ will deleting everything but it will also delete the folder 'today' which I don't want it to do. I can't do RMDIR /S /Q C:\files\today\somefolder\ as 'today' may contain files which'll be left out. I know I can run multiple commands to achive this (such as re-creating the folder afterwards) but was hoping it could be done with just one.
 
Unless I've misinterpreted, won't...

DEL /Q C:\files\today\*.*

...do what you want?

That'll remove all files within the "today" directory, but not actually delete the directory.
 
Last edited:
simister; that will only delete files not folders within the today folder.


This seems to work (test in a VM :p).

PHP:
:: Remove all files and subfolders but NOT the root folder
:: From tip 617 at JsiFAQ.com
@echo off
pushd %1
del /q *.* 
for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
popd
http://ss64.com/nt/del.html

Basically create a batch file called say deltree.bat and then call it with:
deltree.bat files\today
 
Back
Top Bottom