TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ROBBO on March 12, 2014, 04:34:46 AM

Title: Delete bak files older than 1 day
Post by: ROBBO on March 12, 2014, 04:34:46 AM
Hi,

Currently I use this shell command: (COMMAND "SHELL" "DEL /S \"C:\\Temp_Acad\\Backup\\*.bak\" /Q")within my acaddoc.lsp to delete ALL bak files once a day. BUT how can this be adapted to only delete bak files older than 1 day?

Any help or guidance with this would be much appreciated.

Many thanks in advance, Robbo.
Title: Re: Delete bak files older than 1 day
Post by: kruuger on March 12, 2014, 05:01:55 AM
Hi,

Currently I use this shell command: (COMMAND "SHELL" "DEL /S \"C:\\Temp_Acad\\Backup\\*.bak\" /Q")within my acaddoc.lsp to delete ALL bak files once a day. BUT how can this be adapted to only delete bak files older than 1 day?

Any help or guidance with this would be much appreciated.

Many thanks in advance, Robbo.
compare file date/time
Code: [Select]
(vl-file-systime "d:\\txt.lsp")with system time:
Code: [Select]
; =========================================================================================== ;
; Zwraca date/czas systemowa(y) / Return system date/time                                     ;
;  Format [STR] -                                                                             ;
;   ----- Data / Date -----    |   ---- Czas / Time ----                                      ;
;   D       ->   5             |   H       ->   4                                             ;
;   DD      ->   05            |   HH      ->   04                                            ;
;   DDD     ->   Sat           |   MM      ->   53                                            ;
;   DDDD    ->   Saturday      |   SS      ->   17                                            ;
;   M       ->   9             |   MSEC    ->   506                                           ;
;   MO      ->   09            |   AM/PM   ->   AM or PM                                      ;
;   MON     ->   Sep           |   am/pm   ->   am or pm                                      ;
;   MONTH   ->   September     |   A/P     ->   A  or P                                       ;
;   YY      ->   89            |   a/p     ->   a  or p                                       ;
;   YYYY    ->   1989          |                                                              ;
; ------------------------------------------------------------------------------------------- ;
; (cd:SYS_GetDateTime "DDD\",\" DD MON YYYY - H:MMam/pm")                                     ;
; =========================================================================================== ;
(defun cd:SYS_GetDateTime (Format)
  (menucmd (strcat "m=$(edtime,$(getvar,DATE)," Format ")"))
)



also total commander can do this for you
http://www.ghisler.com/


k.
Title: Re: Delete bak files older than 1 day
Post by: ROBBO on March 12, 2014, 05:22:38 AM
Thank you kruuger for your prompt reply.

I am not sure how to implement this with my acaddoc.lsp being new to lisp.

Cheers, Robbo.
Title: Re: Delete bak files older than 1 day
Post by: Kerry on March 12, 2014, 06:01:11 AM
Code - Text: [Select]
  1. :: deleteYesterdaysBakFiles.BAT
  2. :: kdub 2014.03.12
  3.  
  4. echo delete bak files older than 1 day ago
  5. forfiles /p "C:\Temp_Acad\Backup" /s /m *.bak /C "cmd /c echo @path" /d -1
  6.  
  7. forfiles /p "C:\Temp_Acad\Backup" /s /m *.bak /c "cmd /c Del @path" /d -1
  8. pause
http://ss64.com/nt/
http://ss64.com/nt/forfiles.html

A variation of this works for me ... I use -14 in place of -1
All care, no responsibility

A piccy
(http://i57.tinypic.com/2wq7fck.png)
Title: Re: Delete bak files older than 1 day
Post by: kruuger on March 12, 2014, 06:06:09 AM
Thank you kruuger for your prompt reply.

I am not sure how to implement this with my acaddoc.lsp being new to lisp.

Cheers, Robbo.
Code: [Select]
(defun _BAK (Name / fl st)
  (setq fl (vl-file-systime Name)
        st (read (strcat "(" (cd:SYS_GetDateTime "YYYY M DD") ")"))
  )
  (and
    (eq (car fl) (car st))
    (eq (cadr fl) (cadr st))
    (< (- (caddr st) (cadddr fl)) 1)
  )
)

Code: [Select]
(if (_bak "file.txt")
  ... file ...
  ... delete ...
)
k.
Title: Re: Delete bak files older than 1 day
Post by: ROBBO on March 12, 2014, 06:30:38 AM
Thank you Kerry.

Made a slight tweak. Changed pause to exit.

Added (command "shell" "deleteYesterdaysBakFiles.bat") to my acacaddoc.lsp to run the batch file on start-up.

Cheers, Robbo.  :kewl:
Title: Re: Delete bak files older than 1 day
Post by: Kerry on March 12, 2014, 06:33:28 AM

My pleasure.
I'm pleased it suits your requirements.
Title: Re: Delete bak files older than 1 day
Post by: Krushert on March 12, 2014, 12:15:37 PM
Nice.  Got to keep this one in mind.
Title: Re: Delete bak files older than 1 day
Post by: ChrisCarlson on March 13, 2014, 08:09:19 AM
Is there a reason to delete .bak files? No matter how old the file is, if someone comes in and makes a wrong change, the .bak would come in handy. Do people delete the files for space (eg; hard drive) purposes?
Title: Re: Delete bak files older than 1 day
Post by: dgorsman on March 13, 2014, 10:19:35 AM
Our drawings are on the network, so they get covered by the nightly incremental backups.  The BAKs are therefore redundant, so we sweep them out nightly prior to the backup.  Even if we used a BAK redirect to the temp folder its a good idea to keep the temp folder free of otherwise useless files.