Compare two files in autolisp

Compare two files in autolisp

Anonymous
Not applicable
1,530 Views
1 Reply
Message 1 of 2

Compare two files in autolisp

Anonymous
Not applicable

Hello,

Is it possible, in autolisp, to compare two files located in two different places and replace the oldest by the most recent?

For example, the file on my network "R" is my master file. I would like to compare the file on my "C" disk with the one on the "R" disk. If the file's date of the "R" disk is newer than the one's of the "C" disk, then replace the "C" disk file with the "R" disk one.

0 Likes
Accepted solutions (1)
1,531 Views
1 Reply
Reply (1)
Message 2 of 2

Ranjit_Singh
Advisor
Advisor
Accepted solution

@sleroux wrote:

.....
For example, the file on my network "R" is my master file. I would like to compare the file on my "C" disk with the one on the "R" disk. If the file's date of the "R" disk is newer than the one's of the "C" disk, then replace the "C" disk file with the "R" disk one.


Try below code. minimal testing.

(defun c:somefunc  (/ dat1 dat2 filobj fsobj path)
 (setq fsobj (vlax-get-or-create-object "scripting.filesystemobject")
       dat1  (vlax-get (vlax-invoke fsobj 'getfile (setq path (getfiled "Select C: drive file" "c:\\" "txt" 0)))
                       'datelastmodified)
       dat2  (vlax-get (setq filobj (vlax-invoke fsobj 'getfile (getfiled "Select R: drive file" "r:\\" "txt" 0)))
                       'datelastmodified))
 (and (> dat2 dat1) (vlax-invoke filobj 'copy path :vlax-true))
 (vlax-release-object fsobj)
 (princ))
0 Likes