Message 1 of 4
Lisp to copy file if modified
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Need someone better at lisp than me, trying to use lisp to copy a file from one location to another if date modified of source file is newer than destination file. Put some pieces together but doesn't quite work as expected. I think systime looks at date created for file vs date modified? Any suggestions?
(defun c:copyIfModified (/ sourceFile destFile sourceDate destDate)
(setq sourceFile "N:\\CAD\\Details\\sample.dwt")
(setq destFile "C:\\CAD\\Details\\sample.dwt")
;; Get the last modified date of the source file
(setq sourceDate (vl-file-systime sourceFile))
;; Check if the destination file exists
(if (findfile destFile)
(progn
;; Get the last modified date of the destination file
(setq destDate (vl-file-systime destFile))
;; Compare the source and destination file dates
(if (/= sourceDate destDate)
(progn
;; If the dates are different, delete original and copy the source file to the destination
(vl-file-delete destFile)
(vl-file-copy sourceFile destFile)
(princ "\nFile copied1.")
)
(princ "\nNo changes detected.")
)
)
(progn
;; If the destination file doesn't exist, copy the source file to the destination
(vl-file-copy sourceFile destFile)
(princ "\nFile copied2.")
)
)
(princ)
)