BUG: VBApp FileCopy Updates Destination File's Date & Time Stamp |
Q113958
The FileCopy statement in Visual Basic, Applications Edition does not maintain the Date and Time stamp of the source file when the destination file is copied. Unlike the MS-DOS Copy command and the FileCopy statement in Visual Basic version 3.0, the time stamp of the destination file shows the actual time the copy occurs.
Because the time stamp placed on the file is based on the current time, setting the system time to the time stamp of the source file prior to copying the file establishes the same time stamp on the destination file. Below is a sample piece of code to copy a file that maintains the same time stamp:
Sub TestFileCopy()
Dim datOriginalDateTime As Date
Dim datSourceTimeStamp As Date
Const cSourceFile = "C:\AUTOEXEC.BAT"
Const cDestFile = "C:\AUTOEXEC.OLD"
' Obtain Date/Time Stamp of the Source file:
datSourceTimeStamp = FileDateTime(cSourceFile)
' Store Current time in a temporary variable:
datOriginalDateTime = Now()
' Set System time to that of the Source File:
Date = datSourceTimeStamp
Time = datSourceTimeStamp
FileCopy cSourceFile, cDestFile
' Restore System time to correct time:
Date = datOriginalDateTime
Time = datOriginalDateTime
MsgBox "Source Date = " & FileDateTime(cSourceFile) & Chr(13) & _
Chr(10) & "Destination Date = " & FileDateTime(cDestFile)
End Sub
Microsoft has confirmed this to be a bug in the products listed above. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
Sub TestFileCopy()
Const cSourceFile = "C:\autoexec.bat"
Const cDestFile = "C:\autoexec.old"
FileCopy cSourceFile, cDestFile
MsgBox "Source Date = " & FileDateTime(cSourceFile) & Chr(13) & _
Chr(10) & "Destination Date = " & FileDateTime(cDestFile)
End Sub Additional query words: buglist1.00
Keywords :
Issue type : kbbug
Technology : kbExcelSearch kbZNotKeyword6 kbExcel500 kbProjectSearch kbVBASearch kbZNotKeyword3 kbProject400
|
Last Reviewed: January 17, 2001 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |