Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,

I want to know how to create a .bat file to delete all files and folders older than 1 day. I created the next script, but I dont want to delete my .bat file, any suggestions?

VB
@echo off
:: current folder
set dump_path="%CD%"

:: time
set max_days=1

:: remove all files
forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd  /c del /q @path"

:: remove all directories
forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"
Posted

1 solution

Exclude %0 ? Or give it a CMD extension instead?
 
Share this answer
 
Comments
abrchaves 18-Dec-14 18:12pm    
Sorry, I dont understand your answer. Could you please give me an example?
PIEBALDconsult 18-Dec-14 18:34pm    
No.
abrchaves 18-Dec-14 19:23pm    
Great!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900