Set File Date and Time Stamps

Problem

Access makes it easy to retrieve the modification date and time for files on disk, using the FileDateTime function. In one application, though, you need to be able to reset the last-modification date of files manually; the Access FileCopy function doesn’t reset file date and time stamps, and you’d like copied files to have the current time. Is there a Windows API call that allows you to set file date and time stamps?

Solution

Windows provides the GetFileTime and SetFileTime API functions. Both work with three different date/time values: date of creation, date of last access, and date of last write. You want to preserve the date of creation and update the dates of last access and update. The code shown in this example will allow you to do this.

The sample form, frmTimeStamp, allows you to select a filename. The function then displays the date and time of last modification for the file, as shown in Figure 11-13. In addition, you can set a new file date, time, or both (the function retains whichever setting you don’t change, if you just change one).

frmTimeStamp shows a selected file’s modification date and time

Figure 11-13. frmTimeStamp shows a selected file’s modification date and time

To set file date and time information in your own applications, follow these steps:

  1. Import the module basTimeStamp from 11-11.MDB. This module includes the type definitions and Windows API declarations you’ll need, as well ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.