Creating batch file to delete files and subfolders. Get answers from your peers along with millions of IT pros who visit Spiceworks. I have a bat file I made to run nightly before a backup happens to delete the contents of a dir. THe bat works but it does not delete any of the folders in the directories. Feb 13, 2018 I want to delete a folder with all files and subfolders using a bat file. I have tried the following, but it is not working: @DEL D:PHPProjectstestprojectReleasetestfolder. Can anybody h.
i need to remove the files from a folder every 4 hours. Otherwise storage folder will be filled with files and production server will be hang.
user9950user9950
3 Answers
You could create a batch file to delete the files in the subfolder, then create a scheduled task to run the batch file every 4 hours.
![Folder Folder](/uploads/1/2/4/8/124804897/625723409.png)
Since the windows scheduler doesn't allow for hourly tasks you would have to go into the advanced options and create multiple daily tasks that are offset by 4 hours from each other.
NateNate
There is a vbs script (google for deleteoldfiles.zip) that we use to delete files that are older than a certain number of days from our fileserver. Not sure if it can be configured to work in 4 hours, but it would be a good place to start.
Brent Brent
To delete all files from a storage folder, say C:Temp, every four hours, I would use the following biterscript.
Biterscripting can be downloaded from http://www.biterscripting.com . The last time I checked, it was free.
I am enclosing the $file in the delete command in double quotes in case the file or path may contain spaces or other special characters.
![File File](/uploads/1/2/4/8/124804897/452407056.jpg)
Patrick
PatrickMc