Computer Hope

Microsoft => Microsoft DOS => Topic started by: TosunPASA on May 31, 2021, 11:36:46 AM

Title: how i can delete old files ?
Post by: TosunPASA on May 31, 2021, 11:36:46 AM
hello
i have backup directory  (d:\SQL-Backup\.)

and i wanna delete 7-15-30-60 days ago "rar" files  (base is file created day.. because.... sql backup starting everyday 22pm and backup working everyday)

why different time ? have multi diffrent program backup directory and this batch will work different time line

could you help me ?

thx
Title: Re: how i can delete old files ?
Post by: Sidewinder on June 01, 2021, 07:52:30 AM
I think the easiest way would be to use forfiles.

Code: [Select]
set agefactor=7

forfiles /p d:\SQL-Backup /s /d -%agefactor% /m *.rar ^
/c "cmd /c echo @PATH older than %agefactor% days"

I prefer not to write destructive code, so as written the snippet will just list the files. You can change the echo command to a del command once you are satisfied with the results. Also change the value of agefactor in the first line as needed. Note: Enter the agefactor as a positive number, it will be converted to a negative number in the code.

Good luck  8)