See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: Lips to delete all fines in a folder, older than 6 months.

  1. #1
    I could stop if I wanted to jpcadconsulting347236's Avatar
    Join Date
    2011-09
    Posts
    267
    Login to Give a bone
    0

    Default Lips to delete all fines in a folder, older than 6 months.

    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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    James Pertusi

    CAD Applications Consultant
    1 (646) 773 4834
    www.jpcadconsulting.com

  2. #2
    Programming Moderator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,402
    Login to Give a bone
    1

    Default Re: Lips to delete all fines in a folder, older than 6 months.

    You assume vl-File-Systime returns non-Nil:

    Code:
      (foreach file
               (mapcar (function (lambda (x) (strcat "C:/_Autosave/" x)))
                       (vl-directory-files "C:/_Autosave/" "*.*" 1)
               )
        (if (not (vl-file-systime file))
          (prompt (strcat "\n** No systime for \"" file "\" ** "))
        )
      )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 32GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  3. #3
    I could stop if I wanted to jpcadconsulting347236's Avatar
    Join Date
    2011-09
    Posts
    267
    Login to Give a bone
    0

    Default Re: Lips to delete all fines in a folder, older than 6 months.

    Thanks as always BlackBox, working like a charm!

    Quote Originally Posted by BlackBox View Post
    You assume vl-File-Systime returns non-Nil:

    Code:
      (foreach file
               (mapcar (function (lambda (x) (strcat "C:/_Autosave/" x)))
                       (vl-directory-files "C:/_Autosave/" "*.*" 1)
               )
        (if (not (vl-file-systime file))
          (prompt (strcat "\n** No systime for \"" file "\" ** "))
        )
      )
    James Pertusi

    CAD Applications Consultant
    1 (646) 773 4834
    www.jpcadconsulting.com

  4. #4
    Programming Moderator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,402
    Login to Give a bone
    0

    Default Re: Lips to delete all fines in a folder, older than 6 months.

    Quote Originally Posted by jpcadconsulting347236 View Post
    Thanks as always BlackBox, working like a charm!
    Cheers dude.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 32GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

Similar Threads

  1. Delete files older than XX days
    By jpcadconsulting347236 in forum Bridging the Gap: LISP -> .NET -> LISP
    Replies: 1
    Last Post: 2018-04-17, 06:43 PM
  2. Autocad Lips to copy dimension text tol clipboard
    By TheDetailer in forum AutoLISP
    Replies: 2
    Last Post: 2013-02-12, 08:11 AM
  3. Lips routine for special Array
    By ionutste in forum AutoLISP
    Replies: 7
    Last Post: 2012-04-03, 07:16 AM
  4. How was the past 12 months? How will the next 12 months be?
    By Brian Myers in forum Local User Groups - General
    Replies: 2
    Last Post: 2007-01-22, 05:49 AM
  5. 5 Months With Revit - Backup Folder
    By zenomail105021 in forum Revit Architecture - Wish List
    Replies: 6
    Last Post: 2005-09-12, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •