Jump to content

Lisp listing .lsp on folder with 7 days from date modified


RBrigido

Recommended Posts

Hello all masters,

 

I've a lisp here that I would like to list all LISP Files modified 7 days ago, but it's not working as I would like to see.

 

I did a trial:

 

(defun list-modified-files (directory days)
  (if (vl-file-directory-p directory)
      (progn
        (setq today (getvar "CDATE"))
        (setq limit (- today (* 7 days)))
        (setq modified-files '())
        (setq files (vl-directory-files directory "*.lsp"))
        (if (null files)
            (princ "\nNo Lisp files found in the directory.")
          (progn
            (foreach file files
              (setq file-path (strcat directory "\\" file))
              (if (vl-file-directory-p file-path)
                  (progn
                    (setq modification-date (vl-file-systime file-path))
                    (if (> modification-date limit)
                        (progn
                          (princ (strcat "\nFile: " file ", Modification Date: " (rtos modification-date)))
                          (princ " (Modified in the last 7 days)")
                          (setq modified-files (cons file modified-files)))
                      (progn
                        (princ (strcat "\nFile: " file ", Modification Date: " (rtos modification-date)))
                        (princ " (Not modified in the last 7 days)"))))
                (princ (strcat "\nFile: " file ", not found")))))
            (princ "\nAll files processed.")))
    (princ "\nDirectory not found."))
  (if (null modified-files)
      (princ "\nNo Lisp file modified in the last 7 days.")
    (progn
      (princ "\nLisp files modified in the last 7 days:\n")
      (foreach file modified-files
        (princ (strcat "\n- " file))))))

(list-modified-files "FOLDER-PATH-HERE" 7)

 

 

Could someone give me some idea about what's going on?

 

Kind regards,

Rodrigo

Edited by RBrigido
Link to comment
Share on other sites

I'd change starting :

(defun list-modified-files (directory days)

to :

(defun list-modified-files (directory weeks)

 

And also this line :

(setq limit (- today (* 7 days)))

to :

(setq limit (- today (* 7 weeks)))

Link to comment
Share on other sites

I find outputting to a text file to be easier

 

  1. you don't have to keep scrolling up to see the info
  2. it saved outside of cad and cuts down on command prompt spam.

 

 Also your not localizing your variables so they persist even after the lisp has ran. if they aren't overwritten the next time the lisp is called it would cause these issues.

 

;;----------------------------------------------------------------------------;;
;; output to text file lisp files that have been modified in the last 7 days
(defun lst-mod-files (dir weeks / today limit mod-files nomod-files files file-path mod-date)
  (if (vl-file-directory-p dir)
    (progn
      (setq today (getvar 'CDATE))
      (setq limit (- today (* 7 weeks)))
      (setq mod-files '() nomod-files '())
      (if (setq files (vl-directory-files dir "*.lsp"))
        (foreach file files ;foreach doesn't need a (progn to run mulitple lines
          (setq file-path (strcat dir "\\" file))
          (if (> (vl-file-systime file-path) limit)
            (setq mod-files (cons file mod-files))
            (setq nomod-files (cons file nomod-files))
          )
        )
        (princ (strcat "\nNo Lisp files found in folder:" dir))
      )
    )
  )
  (if (or mod-files nomod-files)
    (progn
      (setq F (open (strcat (getenv "userprofile") "\\Documents\\ouput.TXT") "w"))  ;create Readme file in Documents folder
      (write-line "Lisp files modified in the last 7 days:" F)
      (foreach file mod-files
        (write-line file F)
      )
      (write-line " " F)
      (write-line "Lisp files Not modified in the last 7 days:" F)
      (foreach file nomod-files
        (write-line file F)
      )
      (close F)
      (startapp "NOTEPAD" (strcat (getenv "userprofile") "\\Documents\\ouput.TXT"))
    )
    (princ "\nNo Lisp file modified in the last 7 days.")
  )
  (princ)
)

(lst-mod-files "FOLDER-PATH-HERE" 7)

 

Edited by mhupp
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...