Author Topic: Retrieve file creation date  (Read 5173 times)

0 Members and 1 Guest are viewing this topic.

Sebb77

  • Guest
Retrieve file creation date
« on: October 04, 2010, 10:56:12 AM »
I wonder if there's a way to retrieve the date a file was created, in LiSP. And i mean any file type, not just the current drawing.
Thanks for any hint.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Retrieve file creation date
« Reply #1 on: October 04, 2010, 11:07:53 AM »
Some examples:

Code: [Select]
;;-----------------=={ File Last Modified }==-----------------;;
;;                                                            ;;
;;  Returns the Last Modified property of a file in Julian    ;;
;;  time                                                      ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  file - full filepath of file to query                     ;;
;;------------------------------------------------------------;;
;;  Returns:  Last Modified Date (Julian), else nil           ;;
;;------------------------------------------------------------;;

(defun LM:FileLastModified ( file / fso fObj date )
  (vl-load-com)
  ;; © Lee Mac 2010

  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (cond (   (zerop (vlax-invoke fso 'FileExists file)))

        (   (setq fObj (vlax-invoke-method fso 'GetFile file)
                  date (+ 2415019 (vlax-get fObj 'DateLastModified)))))
 
  (vlax-release-object fso)

  date
)

;;--------------------=={ File Created }==--------------------;;
;;                                                            ;;
;;  Returns the DateCreated property of a file in Julian      ;;
;;  time                                                      ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  file - full filepath of file to query                     ;;
;;------------------------------------------------------------;;
;;  Returns:  Creation Date (Julian), else nil                ;;
;;------------------------------------------------------------;;

(defun LM:FileCreated ( file / fso fObj date )
  (vl-load-com)
  ;; © Lee Mac 2010

  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (cond (   (zerop (vlax-invoke fso 'FileExists file)))

        (   (setq fObj (vlax-invoke-method fso 'GetFile file)
                  date (+ 2415019 (vlax-get fObj 'DateCreated)))))
 
  (vlax-release-object fso)

  date
)

;;--------------------=={ File Info }==-----------------------;;
;;                                                            ;;
;;  Returns the Last Modified property of a file in Julian    ;;
;;  time                                                      ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  file - full filepath of file to query                     ;;
;;------------------------------------------------------------;;
;;  Returns:                                                  ;;
;;  List of file information:                                 ;;
;;   <FileName>         ~ name of file                        ;;
;;   <DateCreated>      ~ Julian date of file creation        ;;
;;   <DateLastAccessed> ~ Julian date of file last accessed   ;;
;;   <DateLastModified> ~ Julian date of file last modified   ;;
;;   <Size>             ~ Size of file in bytes               ;;
;;------------------------------------------------------------;;

(defun LM:FileInfo ( file / fso fObj info )
  (vl-load-com)
  ;; © Lee Mac 2010

  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (cond (   (zerop (vlax-invoke fso 'FileExists file)))

        (   (setq fObj (vlax-invoke-method fso 'GetFile file))

            (setq info (mapcar '(lambda ( property functionn ) ((eval functionn) (vlax-get fObj property)))
                         '(Name DateCreated DateLastAccessed DateLastModified Size)
                         '((lambda ( x ) x )
                           (lambda ( x ) (+ x 2415019))
                           (lambda ( x ) (+ x 2415019))
                           (lambda ( x ) (+ x 2415019))
                           (lambda ( x ) x ))))))
 
  (vlax-release-object fso)

  info
)

(defun LM:FormatDate ( date format )
  ;; © Lee Mac 2010
  (menucmd (strcat "m=$(edtime," date "," format ")"))
)

;; Test Function

(defun c:test ( / f i )
  (vl-load-com)
 
  (if (and (setq f (getfiled "Select File to Query" "" "" 16))
           (setq i (LM:FileInfo f)))

    (princ
      (strcat
        "\n-- Information for: " (car i)
        (apply 'strcat
          (mapcar 'strcat '("\nCreated: " "\nAccessed: " "\nModified: ")
            (mapcar '(lambda ( x ) (LM:FormatDate (rtos x 2 15) "DD.MO.YYYY HH:MM:SS")) (cdr i))
          )
        )
        "\nSize (KB): " (rtos (/ (last i) 1024.) 2 3)
      )
    )
  )

  (princ)
)

Another test function calling the above subs:

Code: [Select]
(defun c:GetCreatedTest ( / f )

  (if (setq f (getfiled "Select File to Query" "" "" 16))
    (print
      (LM:FormatDate (rtos (LM:FileCreated f) 2 15) "DD.MO.YYYY HH:MM:SS")
    )
  )

  (princ)
)
« Last Edit: October 04, 2010, 11:11:37 AM by Lee Mac »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Retrieve file creation date
« Reply #2 on: October 04, 2010, 11:13:05 AM »
There are a myriad of ways to do it but a useful exercise imo is to figure out how to use the information here in a lisp program. Here is an example.

Edit: Feck I am way too slow today. Medic bring me a coffee stat.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Sebb77

  • Guest
Re: Retrieve file creation date
« Reply #3 on: October 04, 2010, 01:17:02 PM »
Thank you guys,
      i am looking closely to your examples. Exactly want i wanted.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Retrieve file creation date
« Reply #4 on: October 04, 2010, 01:19:18 PM »
You're very welcome Sebb  :-)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Retrieve file creation date
« Reply #5 on: November 16, 2010, 04:10:42 PM »
Lee,..

I also Have something similar...
but when time is come to compare 2 files...eaven if the file have been copied..
the result are diffrent.

Code: [Select]
(defun checkDateCreate (file / fso)
  (setq fso
(vla-getinterfaceobject
   (vlax-get-acad-object)
   "Scripting.FileSystemObject"
)
  )
  (rtos
    (vlax-get-property
      (vlax-invoke-method fso 'getfile file)
      'DateCreated
      ;'DateLastAccessed
      ;'DateLastModified
    ) 2 10
  )
)
Keep smile...

rocknor

  • Mosquito
  • Posts: 2
Re: Retrieve file creation date
« Reply #6 on: December 14, 2021, 05:07:09 PM »
When we have to change last modification date of file:

Code: [Select]
       ;; ------------------------<[** Set Last Modified [date] of [file] **]>--------------------------------------------
       ;; Created By: © PaNo 2021 
       ;; patkai.norbi@gmail.com
       ;;
       ;; Example: (SetFileLastModified "f:\\works\\lisp\\test\\somefile.dll" "01/01/2015 8:00:00 AM")
(defun SetFileLastModified ( file date / i fso fObj sh) 
          (vl-load-com)       
  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (setq sh (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application"))
  (if (= (vlax-invoke fso 'FileExists file) -1)
    (progn
   (setq oFolder (vlax-invoke sh 'NameSpace (vl-filename-directory file)))
   (setq oFiles (vlax-invoke oFolder 'Items))
   (setq count (vlax-get oFiles 'Count))
   (setq i 0)
   (while (< i count)
     (setq fItem (vlax-invoke oFiles 'Item i))
(setq filepath (vlax-get fItem 'path))
(if (= (vl-filename-base filepath) (vl-filename-base file))
   (vlax-put fItem 'ModifyDate date)    
)
     (setq i (+ i 1))
   ) ;wend
   (vlax-release-object sh)
    )
    (print (strcat "File not found: " file))
  )
  (vlax-release-object fso)    
    )
   
« Last Edit: December 15, 2021, 07:13:31 PM by rocknor »

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Retrieve file creation date
« Reply #7 on: December 14, 2021, 05:42:22 PM »
Welcome to theSwamp, rocknor.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

rocknor

  • Mosquito
  • Posts: 2
Re: Retrieve file creation date
« Reply #8 on: December 15, 2021, 05:00:34 PM »
Thank you, hello everybody:)