u42093
asked on
FileCopy() changes file time????
I run a VB5(SP3) application that reports differences between files on two drives based on the date/time of the file (as reported by the FileDateTime() function). The app allows the user to copy the newer file over to the other drive (implemented by using the FileCopy() command) in order to synchroinze the two sets of files.
This works fine under Windows 95. However, under Windows NT(SP3), when VB5's FileCopy() command copies a file to the other location, it modifies the time of the target file by adding one second to the new file's time. (Yes, it really does. I didn't believe it myself until I tested it.)
The source file remains unchanged.
This only occurs under Windows NT, and only when the target file in the FileCopy() function is removable media (A: or zip drive). This same scenario does not occur when synching two directories on the same hard drive. (I only have one hard drive, so I can't test whether this occurs between two different hard drives)
Has anybody ever heard of such a thing? Any ideas what's going on?
This works fine under Windows 95. However, under Windows NT(SP3), when VB5's FileCopy() command copies a file to the other location, it modifies the time of the target file by adding one second to the new file's time. (Yes, it really does. I didn't believe it myself until I tested it.)
The source file remains unchanged.
This only occurs under Windows NT, and only when the target file in the FileCopy() function is removable media (A: or zip drive). This same scenario does not occur when synching two directories on the same hard drive. (I only have one hard drive, so I can't test whether this occurs between two different hard drives)
Has anybody ever heard of such a thing? Any ideas what's going on?
ASKER
Hi. Here are the answers to the questions in the previous comment:
1. Yes, it only happens with the FileCopy() method in VB. When I copy the file via Explorer, the date/time is properly carried to the target file.
2. I only have one hard drive, but I also have a diskette drive (A:) and a parallel port zip drive (D:), and a CD-ROM (E:). Most of my file synchronization tasks are between the C: drive and the parallel port zip drive (D:), and it was between C: and D: that I first noticed these problems. So the answer to the questions is, yes, I intended to say to another *drive*.
3. As stated in #2, it's not a network drive, it's the D: zip drive or the A: diskette drive that are the targets of the file copies.
4. I'm glad someone else thinks this is weird, too!!! I'm baffled...
Thanks!!!!!
1. Yes, it only happens with the FileCopy() method in VB. When I copy the file via Explorer, the date/time is properly carried to the target file.
2. I only have one hard drive, but I also have a diskette drive (A:) and a parallel port zip drive (D:), and a CD-ROM (E:). Most of my file synchronization tasks are between the C: drive and the parallel port zip drive (D:), and it was between C: and D: that I first noticed these problems. So the answer to the questions is, yes, I intended to say to another *drive*.
3. As stated in #2, it's not a network drive, it's the D: zip drive or the A: diskette drive that are the targets of the file copies.
4. I'm glad someone else thinks this is weird, too!!! I'm baffled...
Thanks!!!!!
Let me guess. NTFS disk?
Does this sound familiar
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
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.
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
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
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.
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sounds familiar, sort of. This is indeed under NTFS, but there are a few discrepancies/contradictio ns between the published bug and what's happening to my app. But all-in-all it sounds like you've given me both a possible explanation (bug) and a workaround (direct manipulation of the time on the destination file).
The discrepancies are 1) this is not VB5 Applications Edition, it's VB5(SP3) Professional Edition and 2) the time of the copy isn't appearing on the destination file, it's the time of the original source file plus one second. (For example, if the source file's time was 12:02:15, the destination file ends up being 12:02:16 after the copy).
What a strange bug! Thanks for the assistance.
The discrepancies are 1) this is not VB5 Applications Edition, it's VB5(SP3) Professional Edition and 2) the time of the copy isn't appearing on the destination file, it's the time of the original source file plus one second. (For example, if the source file's time was 12:02:15, the destination file ends up being 12:02:16 after the copy).
What a strange bug! Thanks for the assistance.
I presume that this only happens with the FileCopy() method in VB? I.e. it doesn't happen when you copy a file in Explorer.
You say it happens when copying the file to another drive. Do you actually mean drive ("I only have one hard drive") or directory?
If it is another drive, I presume that it's on a network - in which case, are you using an NT server, Novell etc.??
I doubt that I would be able to help you but these are probably questions that other people are liable to ask. It certainly does seem a strange one though.
Good luck.