Hiya gang,

I've got this lisp routine that deletes all files in a backup folder, older than 180 days.

it works great unless there are no files older than 180 days and then it fails with:

"; error: bad argument type: numberp: nil"

I'm not sure how to get it to do nothing if it finds no files that match the criteria.

Hoping you can help me out.

Code:
;;;;;;;;;; Delete Autosave file solder than 180 days ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq dwglst (mapcar '(lambda (x)(strcat "C:/_Autosave/" x))(vl-directory-files "C:/_Autosave/" "*.*" 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) 180)
(vl-file-delete dwg)
)
)
); end if
(setq dwglst nil)
;;;;;;;;; END Delete Autosave file solder than 180 days;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;