PDA

View Full Version : Delete backup files more than a certain age



ccowgill
2009-08-27, 01:35 PM
Currently I have an autosave program running that creates a drawing backup every 10 minutes and saves it in a folder on my hard drive. I would like to get a program that will delete all files automatically that are more than a certain age. I would like it to run automatically at a particular time and delete all files that are older than the previous month (if it ran today it would delete all files older than July 1, if it ran on September 1, it would delete all files older than August 1) Any suggestions?

dgorsman
2009-08-27, 02:45 PM
When the program is loaded, have it clean out any backup drawings that are older than a certain date. While its running, you might also want to have it check for the number of indexed copies and remove the oldest copy before creating a new one.

Opie
2009-08-27, 02:51 PM
Try this routine from LifeHacker.com, "Clean out old files with the Windows Janitor script (http://lifehacker.com/288443/clean-out-old-files-with-the-windows-janitor-script)." You will need to tweak it to fit your needs, but it does work.

jsowinski
2009-08-27, 08:38 PM
Hi-
Here is a bit of code that I use in S::STARTUP. It looks for all drawings in a given directory and deletes any that are older than 30 days automatically. You would need to modify the search path "C:/temp" in both places or use what every means to get your files. Also, change "*.dwg" to "*.bak" or whatever extension your looking for. The main part of the foreach is converting a date (08/27/09) to a julian date.(2455071) Then it compares the calulated date with (getvar "date"). If it is older than 30 days it will automatically be deleted. One other thing. You can change how many days you want it to look for by changing the "30" in the last IF statement to whatever you like. ex.
(if (> (- (fix (getvar "date")) julian) 30)

Almost forgot, it will not delete files that are Read Only.



(setq dwglst (mapcar '(lambda (x)(strcat "C:/Temp/" x))(vl-directory-files "C:/Temp/" "*.dwg" 1)))
(if dwglst
(foreach dwg dwglst
(setq month (cadr (vl-file-systime dwg)))
(setq day (cadddr (vl-file-systime dwg)))
(setq year (car (vl-file-systime dwg)))
(setq a (/ (- 14 month)12))
(setq y (- (+ year 4800) a))
(setq m (- (+ (* 12 a) month) 3))
(setq c1 (/ (+ (* 153 m) 2) 5))
(setq c2 (* 365 y))
(setq c3 (/ y 4))
(setq c4 (/ y 100))
(setq c5 (/ y 400))
(setq julian (fix (- (+ (- (+ (+ (+ day c1) c2) c3) c4) c5) 32045)))
(if (> (- (fix (getvar "date")) julian) 30)
(vl-file-delete dwg)
)
)
); end if
(setq dwglst nil)


Hope this helps.

ccowgill
2009-08-27, 08:46 PM
Hi-
Here is a bit of code that I use in S::STARTUP. It looks for all drawings in a given directory and deletes any that are older than 30 days automatically. You would need to modify the search path "C:/temp" in both places or use what every means to get your files. Also, change "*.dwg" to "*.bak" or whatever extension your looking for. The main part of the foreach is converting a date (08/27/09) to a julian date.(2455071) Then it compares the calulated date with (getvar "date"). If it is older than 30 days it will automatically be deleted. One other thing. You can change how many days you want it to look for by changing the "30" in the last IF statement to whatever you like. ex.
(if (> (- (fix (getvar "date")) julian) 30)

Almost forgot, it will not delete files that are Read Only.



(setq dwglst (mapcar '(lambda (x)(strcat "C:/Temp/" x))(vl-directory-files "C:/Temp/" "*.dwg" 1)))
(if dwglst
(foreach dwg dwglst
(setq month (cadr (vl-file-systime dwg)))
(setq day (cadddr (vl-file-systime dwg)))
(setq year (car (vl-file-systime dwg)))
(setq a (/ (- 14 month)12))
(setq y (- (+ year 4800) a))
(setq m (- (+ (* 12 a) month) 3))
(setq c1 (/ (+ (* 153 m) 2) 5))
(setq c2 (* 365 y))
(setq c3 (/ y 4))
(setq c4 (/ y 100))
(setq c5 (/ y 400))
(setq julian (fix (- (+ (- (+ (+ (+ day c1) c2) c3) c4) c5) 32045)))
(if (> (- (fix (getvar "date")) julian) 30)
(vl-file-delete dwg)
)
)
); end if
(setq dwglst nil)
Hope this helps.
actually that helps a lot, I'm thinking that if I can find a file that is updated everyday, I can use this to compare the systime, and the second item in the list. If the difference is 2 or more, delete the file. Now, all I have to do is find a file that is modified everyday that I can use to compare to.

rkmcswain
2009-08-27, 10:19 PM
FWIW - we use a VBS file that is called from the login script (via GPO) to delete all files in the %temp% directory that are more that "X" days old.

ccowgill
2009-08-28, 11:53 AM
FWIW - we use a VBS file that is called from the login script (via GPO) to delete all files in the %temp% directory that are more that "X" days old.
will a vbs file run on a 64bit OS?

rkmcswain
2009-08-28, 12:33 PM
Looks like it should (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23528652.html)...