What commands can I use (from the command prompt) to delete all files and all subdirectories from a folder, but not delete the folder itself? Basically at the end of the delete, there should be an empty folder.
cd <foldername> del *.*
will delete the files. You'll need to do
rmdir /s <subfolder>
for each subfolder.
Try this in a batch file:
@echo off cd "%1" del *.* /y for /d %%i in (*) do rmdir /s /q "%%i"
Call it something like EmptyDir.bat. Then you can type:
and it will delete the files and folder in that folder, but leave the folder there.
$> wipe.bat myExampleFolder
rmdir /s $1 mkdir $1
With this solution, you may specify relative to current folder or even absolute paths.
Be sure to be aware of dangers. I.e. if the folder you chose to delete does not exists. (That is, why for example
cd <targetdir>| del *.* can be quite dangerous... If you look for other solutions, current-directory-restore might be your friend:
@set OLDDIR=%CD% cd $1 echo do stuff... @cd /d %OLDDIR%