Author Topic: Delete bak files older than 1 day  (Read 3233 times)

0 Members and 1 Guest are viewing this topic.

ROBBO

  • Bull Frog
  • Posts: 217
Delete bak files older than 1 day
« 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.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

kruuger

  • Swamp Rat
  • Posts: 633
Re: Delete bak files older than 1 day
« Reply #1 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.

ROBBO

  • Bull Frog
  • Posts: 217
Re: Delete bak files older than 1 day
« Reply #2 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.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Delete bak files older than 1 day
« Reply #3 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
« Last Edit: March 12, 2014, 06:05:46 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kruuger

  • Swamp Rat
  • Posts: 633
Re: Delete bak files older than 1 day
« Reply #4 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.

ROBBO

  • Bull Frog
  • Posts: 217
Re: Delete bak files older than 1 day
« Reply #5 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:
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Delete bak files older than 1 day
« Reply #6 on: March 12, 2014, 06:33:28 AM »

My pleasure.
I'm pleased it suits your requirements.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Delete bak files older than 1 day
« Reply #7 on: March 12, 2014, 12:15:37 PM »
Nice.  Got to keep this one in mind.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

ChrisCarlson

  • Guest
Re: Delete bak files older than 1 day
« Reply #8 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?

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Delete bak files older than 1 day
« Reply #9 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}