softbless
asked on
Batch file to delete all files
hi guys,
In Windows :
i need batch file script *.cmd or *.bat that delete all the files (Files ONLY, not subfolder) in a particular directory. For example c:\erase
It also erases all the files in subfolders. Kindly note that all the subfolder should not be deleted. So it only delete files, not directories.
In Windows :
i need batch file script *.cmd or *.bat that delete all the files (Files ONLY, not subfolder) in a particular directory. For example c:\erase
It also erases all the files in subfolders. Kindly note that all the subfolder should not be deleted. So it only delete files, not directories.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
And if you want to add the switches: Force, Quiet, and Sub-dir
DEL /q /s /f C:\erace
If your erace folder name contains spaces like "c:\erace this folder\"
DEL /q /s /f "c:\erace this folder"
DEL /q /s /f C:\erace
If your erace folder name contains spaces like "c:\erace this folder\"
DEL /q /s /f "c:\erace this folder"
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
oups!
I misspelled erase in all my posts:
DEL /q /s /f C:\erase >>"%~dpn0.log"
I misspelled erase in all my posts:
DEL /q /s /f C:\erase >>"%~dpn0.log"
ASKER
thanks
You'r welcome!
del /q *
/q is for quiet mode. This will not delete directories (rmdir or deltree could be used for that purpose).
Add /f for deleting readonly files too, the content of the .cmd / .bat should then be :
del /f /q *