Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Development
System Services
Time
Time Reference
Time Functions
 GetFileTime function
GetFileTime function

Applies to: desktop apps only

Retrieves the date and time that a file or directory was created, last accessed, and last modified.

Syntax

BOOL WINAPI GetFileTime(
  __in       HANDLE hFile,
  __out_opt  LPFILETIME lpCreationTime,
  __out_opt  LPFILETIME lpLastAccessTime,
  __out_opt  LPFILETIME lpLastWriteTime
);

Parameters

hFile [in]

A handle to the file or directory for which dates and times are to be retrieved. The handle must have been created using the CreateFile function with the GENERIC_READ access right. For more information, see File Security and Access Rights.

lpCreationTime [out, optional]

A pointer to a FILETIME structure to receive the date and time the file or directory was created. This parameter can be NULL if the application does not require this information.

lpLastAccessTime [out, optional]

A pointer to a FILETIME structure to receive the date and time the file or directory was last accessed. The last access time includes the last time the file or directory was written to, read from, or, in the case of executable files, run. This parameter can be NULL if the application does not require this information.

lpLastWriteTime [out, optional]

A pointer to a FILETIME structure to receive the date and time the file or directory was last written to, truncated, or overwritten (for example, with WriteFile or SetEndOfFile). This date and time is not updated when file attributes or security descriptors are changed. This parameter can be NULL if the application does not require this information.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Not all file systems can record creation and last access times and not all file systems record them in the same manner. For example, on FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). Therefore, the GetFileTime function may not return the same file time information set using the SetFileTime function.

NTFS delays updates to the last access time for a file by up to one hour after the last access. NTFS also permits last access time updates to be disabled. Last access time is not updated on NTFS volumes by default.

Windows Server 2003 and Windows XP/2000:  Last access time is updated on NTFS volumes by default.

For more information, see File Times.

If you rename or delete a file, then restore it shortly thereafter, Windows searches the cache for file information to restore. Cached information includes its short/long name pair and creation time.

Examples

For an example, see Retrieving the Last-Write Time.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

File Times
FILETIME
GetFileSize
GetFileType
SetFileTime
Time Functions

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
FindFirstFile      J_N86   |   Edit   |   Show History
FindFirstFile can also be used to get this info without opening the file. FindFirstFile can also be used to get this info without opening the file.
Tags What's this?: Add a tag
Flag as ContentBug
GENERIC_READ?      aidtopia   |   Edit   |   Show History
Do you actually need GENERIC_READ? Or is it enough to have FILE_READ_ATTRIBUTES (and maybe FILE_READ_EA)?
Tags What's this?: Add a tag
Flag as ContentBug
GetFileAttributesEx can also do this without opening the file      EclecticMonk   |   Edit   |   Show History
As long as you're targeting Windows 2000 or later, GetFileAttributesEx can do this without opening the file as well.
Tags What's this?: Add a tag
Flag as ContentBug
FindFirstFile can also be used to get this info without opening the file.      ptr_b   |   Edit   |   Show History
FindFirstFile can also be used to get this info without opening the file.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker