BUG: VBApp FileCopy Updates Destination File's Date & Time Stamp
ID: Q113958
|
The information in this article applies to:
-
Microsoft Visual Basic, Applications Edition
-
Microsoft Excel for Windows, version 5.0
-
Microsoft Project for Windows, version 4.0
SYMPTOMS
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.
WORKAROUND
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
STATUS
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.
MORE INFORMATION
Steps to Reproduce Problem
- Start Excel, or from the File menu, choose New (ALT, F, N) if Excel
is already running.
- Insert a New module. From the Insert Menu, choose Macro Module
(ALT, I, M, M). Module1 is created by default.
- Insert the following code into Module1:
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
- Run the macro. From the Tools Menu, choose Macro (ALT, T, M).
From the Macro dialog, select the macro TestFileCopy. Then click the
Run button.
The time stamps for the Source and Destination files differ. You would
expect them to be the same. Now try the workaround routine, you will
see the Source and Destination files are the same.
Additional query words:
buglist1.00
Keywords :
Version : :; WINDOWS:4.0,5.0
Platform : WINDOWS
Issue type : kbbug