0

my problem is that I want to store the five oldest files from a directory in a list. Since the software should be safe against time changes done by the user I'm looking for a possibility to extract this information without using the file time. Is there any internal counter implemented in windows that can be extracted from the files meta-data? Or is it possible to set such a counter during the file creation (e.g. in a specific field of the meta-information)?

Best regards NouGHt

NouGHt
  • 31
  • 3
  • in Batch ("Dos-Box") try `dir /?`. `Note the difference in output between `dir /Tc`and `dir/Tw`. If there is no function in c++ (i don't know C++), you could call a short batch from there to get what you need. – Stephan Jun 01 '13 at 06:21

1 Answers1

1

Are you saying you don't want to use "the file time" in case users have modified the files since they were created?

If that is the case, your problem may solved with the information that Windows stores three distinct FILETIMEs for each file: 1) the file's creation time, 2) the file's last access time, 3) the file's last write time.

You would want the first of these. You can get all of them by calling the win api GetFileAttributesEx function passing the file name. The WIN32_FILE_ATTRIBUTE_DATA structure that is returned to you contains all three times.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • The problem is, what happens when the user changes the systemtime. This enables the user to modify the files stored in the database. Or what simply happens when the computer change the time zone (e.g. due to traveling). Here an internal numeration could be the solution. My question is, is there a Windows mechanism that enumerates the files in a folder with increasing index if one is created? – NouGHt Jun 01 '13 at 08:21
  • Right I understand. There is no such mechanism in the OS. – Mike Kinghan Jun 01 '13 at 11:03
  • 1
    But note a) Changing the system time has no effect on the creation time of *pre-existing* files. b) Time-zone movements, if correctly tracked by the system time, will not mess with file creation times, which are in UTC. c) Files can only get to be "out of the right order" time-stamp-wise when one of them is created while the system time is set *wrongly in the past so much as to predate the creation of an actually older file*. Is it really your app's responsibility to defend against that scenario? – Mike Kinghan Jun 01 '13 at 11:29
  • @NouGHt: Note also that anyone can call `SetFileTime` and replace the times with whatever they want. You can't assume that the times listed there are always the times. – Billy ONeal Jun 01 '13 at 21:36