BUG: VBApp FileCopy Updates Destination File's Date & Time Stamp

Last reviewed: July 29, 1997
Article ID: Q113958
The information in this article applies to:
  • Microsoft Visual Basic, Applications Edition, version 1.0
  • Microsoft Excel, version 5.0
  • Microsoft Project, 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

  1. Start Excel, or from the File menu, choose New (ALT, F, N) if Excel is already running.

  2. Insert a New module. From the Insert Menu, choose Macro Module (ALT, I, M, M). Module1 is created by default.

  3. 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
    
    

  4. 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 : kbcode kbprg
Version : 1.00 4.00 5.00
Platform : WINDOWS
Issue type : kbbug
Solution Type : kbcode


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.