View Full Version : Copy a file without changing the last modified date
ccowgill
2006-11-13, 12:32 PM
using Lisp I can use vl-file-copy to copy a file, but it puts the current date and time stamp, this is a problem when everyone loads AutoCAD at a different times. I would like the file to have the exact same time stamp for all machines to make sure they are identical files. I figure vba might have more capability, I know you can use DOS to copy files and it kept the date, but I dont know a thing about vba and if figure it is probably more powerful than VLISP
any help would be appreciated
rkmcswain
2006-11-13, 01:06 PM
This example, in lisp, will keep the original file date.
(setq wshFSO (vlax-create-object "Scripting.FileSystemObject"))
(vlax-invoke-method wshFSO 'CopyFile "c:\\temp\\t.lin" "c:\\" :vlax-true)
ccowgill
2006-11-13, 01:11 PM
I guess VLISP is more powerful than I thought, you just have to know how to use it.
Thanks, that worked perfectly.
I guess VLISP is more powerful than I thought, you just have to know how to use it.
Thanks, that worked perfectly.
This will be possible for you on pure VBA also:
Make sure that in VBE->Tools->Options->General
in Error Trapping section 'Break on Unhandled Errors'
button is checked
Option Explicit
Option Compare Text
Sub ch_CopyFile()
'' *** Note: Requires reference to "Microsoft Scripting Runtime" library
Dim FS As FileSystemObject
Dim oFolder As Folder
Dim oFile As File
Dim currFolder As String
Dim copyFolder As String
Dim shortName As String
Dim filName As String
currFolder = "D:\WORK\"
copyFolder = "C:\COPY_WORK\"
shortName = "ABC.TXT"
filName = currFolder & shortName
On Error GoTo ErrHandler
Set FS = CreateObject("Scripting.FileSystemObject")
Set oFolder = FS.GetFolder(copyFolder)
For Each oFile In oFolder.Files
If oFile.Name = shortName Then
MsgBox "File " & shortName & "already exist"
Exit For
Exit Sub
End If
Next oFile
FS.CopyFile filName, copyFolder
Exit Sub
ExitHere:
On Error Resume Next
Set oFile = Nothing
Set oFolder = Nothing
Set FS = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " & Err.Description
Resume ExitHere
End Sub
~'J'~
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.