Link to home
Create AccountLog in
Avatar of softbless
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.
Avatar of Didier Vx
Didier Vx
Flag of France image

Juste create a .cmd or .bat file and put something like that in it :

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 *
ASKER CERTIFIED SOLUTION
Avatar of telczj9
telczj9

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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"
SOLUTION
Link to home
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"
Avatar of softbless
softbless

ASKER

thanks
You'r welcome!