How to change the date/time on a file from VB?


This example will show you how to COPY the file-time/date from one file to another. If anyone has information on how to independently set those attributes, please contact me.

Put this in your declaration-section:
Declare Function SetTime Lib "SETUPKIT.DLL" (ByVal A$, ByVal b$) As Integer

Then use this function to copy the date/time from the sourcefile to the destinationfile:
Result = SetTime(SourceFile$, DestinationFile$)

This following hint came from Fahad Saadah (Fahad@trilogy.com.au):

You can use a simple trick along with the Win API that copies one file's time to another.
You can create a dummy file (and save it). It will have the system's current date and time. Then you use this dummy file to copy it's date and time info to another file using the SetTime API function.

The only problem of this method is that you cannot set the date/time to specific value.

More input on this subject is appreciated.


Mail to Daniel Wiman <daniel@wimania.com>
Online since June 1996, updated 971103
<- The VB home
<- Daniels homepage