PDA

View Full Version : File dates



pcsyoga
2004-06-18, 03:34 PM
I am trying to compare the dates on various files.
I have been using vl-file-systime, which is unreliable, it often returns nil for inexplicable (at least to me) reasons. I now Doslib has a function to pull out a file's date, but is there another way to do it, so I don't have to rely on outside software?

stig.madsen
2004-06-18, 04:57 PM
If you don't want to use either, you could again consult the Windows Scripting Host. But don't forget, that's also "outside software".

File dates accessed by the FileSystemObject are in a 1900-based format that's not easy to convert with AutoLISP. Jon Fleming provides an excellent conversion routine in his ADOLISP Database Library (http://www.fleming-group.com/ConsultingIndex.htm) (excellent stuff alltogether). The routine below uses it. Of course you could just compare the raw julian dates it retrieves from the file.


;; Note: Some VL-CATCH-ALL-thingies should be added in strategic places!
(defun fDate (file / fso date)
(and (not file)(setq file (getfiled "" "" "" 0)))
(cond ((setq fso (vlax-create-object "Scripting.FilesystemObject"))
(and (eq :vlax-true (vlax-invoke-method fso 'FileExists file))
(setq file (vlax-invoke-method fso 'GetFile file))
(setq date (vlax-get-property file 'DateCreated))
(setq date (1900BasedJulianToCalender date))
(vlax-release-object file)
)
(vlax-release-object fso)
)
)
date
)

stig.madsen
2004-06-18, 05:04 PM
By the way, if you need modication or last accessed date instead of creation date - or some other property - then look up the references at http://msdn.microsoft.com/library/default.asp?. Just search for FileSystemObject.

pcsyoga
2004-06-23, 11:43 AM
Thanks for your help, Stig. That will put me where I want to go.