Page 1 of 1

File modification date

Posted: Sat Jun 29, 2024 2:44 pm
by jak64
File modification date

Good morning,
I tested the example program in Purebasic to retrieve the modification date of a file.

It systematically returns 01/01/1970 regardless of the parameter we put (#PB_Date_Created, #PB_Date_Accessed or #PB_Date_Modified)???

I would also like to retrieve the modification time of the file.

Can you help me ?

I am in PurBasic version 6.10, 64 bits, under Windows 11 Pro.

Code: Select all

  Repertoire$ = GetHomeDirectory()  ; Liste tous les fichiers et les dossiers du répertoire racine de l'utilisateur qui est actuellement logué (Home)
  If ExamineDirectory(0, Repertoire$, "*.*")  
    While NextDirectoryEntry(0)
      If DirectoryEntryType(0) = #PB_DirectoryEntry_File
        Type$ = " [Fichier] "
        Taille$ = " (Taille : " + DirectoryEntrySize(0) + ")"
        DateAcces = GetFileDate(DirectoryEntryName(0), #PB_Date_Accessed)
      Else
        Type$ = " [Dossier] "
        Taille$ = "" ; Un Dossier n'a pas de taille
        DateAcces = DirectoryEntryDate(0, #PB_Date_Accessed)
      EndIf
      
      Debug Type$ + DirectoryEntryName(0) + Taille$
      Debug "Dernier accès le : " + FormatDate("%dd/%mm/%yyyy", DateAcces)
      Debug ""
    Wend
    FinishDirectory(0)
  EndIf

Re: File modification date

Posted: Sat Jun 29, 2024 3:28 pm
by Axolotl
Hi jak64,
I am pretty sure you will find it out by yourself....
See my changes to your code for help.

Code: Select all

  Repertoire$ = GetHomeDirectory()  ; Liste tous les fichiers et les dossiers du répertoire racine de l'utilisateur qui est actuellement logué (Home)

  Repertoire$ = RTrim(Repertoire$, #PS$)  : Debug Repertoire$   ; <-- added 

  If ExamineDirectory(0, Repertoire$, "*.*")  
    While NextDirectoryEntry(0)
      If DirectoryEntryType(0) = #PB_DirectoryEntry_File
        Type$ = " [Fichier] "
        Taille$ = " (Taille : " + DirectoryEntrySize(0) + ")"
        DateAcces = DirectoryEntryDate(0, #PB_Date_Accessed)                   ; <-- added 
;       DateAcces = GetFileDate(DirectoryEntryName(0), #PB_Date_Accessed)      ; <-- removed 
      Else
        Type$ = " [Dossier] "
        Taille$ = "" ; Un Dossier n'a pas de taille
        DateAcces = DirectoryEntryDate(0, #PB_Date_Accessed) 
      EndIf
      
      Debug Type$ + DirectoryEntryName(0) + Taille$
      Debug "Dernier accès le : " + FormatDate("%dd/%mm/%yyyy", DateAcces)
      Debug ""
      ; -- added the next three lines ... 
      Debug "  DateAcces.1 = " + FormatDate("%dd/%mm/%yyyy", GetFileDate(DirectoryEntryName(0), #PB_Date_Accessed))
      Debug "  DateAcces.2 = " + FormatDate("%dd/%mm/%yyyy", GetFileDate(Repertoire$ + #PS$ + DirectoryEntryName(0), #PB_Date_Accessed))
      Debug ""
    Wend
    FinishDirectory(0)
  EndIf

Re: File modification date

Posted: Sat Jun 29, 2024 3:39 pm
by Marc56us
Need to have the help corrected, as Jak64' code is the example provided in the french help (online and in .CHM).
GetFileDate()
(There's no example on the english help page, so this might be a good opportunity to add it too (corrected)?).

:arrow: Please moderator, move this topic to Bugs - Documentation :wink:

Re: File modification date

Posted: Sat Jun 29, 2024 3:56 pm
by Comfort
That be the ExamineDirectory() example.

Re: File modification date

Posted: Sat Jun 29, 2024 4:01 pm
by jak64
Thanks Axolotl and Marc56us.

I would also like to have the modification time as we do when using Windows Explorer.

Is it possible ?

thank you

Re: File modification date

Posted: Sat Jun 29, 2024 4:05 pm
by Marc56us
jak64 wrote: Sat Jun 29, 2024 4:01 pm I would also like to have the modification time as we do when using Windows Explorer.
Simply change mask

Code: Select all

FormatDate("%dd/%mm/%yyyy %hh:%ii:%ss", GetFileDate(Rep...
(see FormatDate() help)

Re: File modification date

Posted: Sat Jun 29, 2024 4:07 pm
by Axolotl
Confirmed for german online help, too. The example is not existing.

The french page shows an extended example of ExamineDirectory().
IMHO the example is not good to explain GetFileDate() anyway. (see my example).

additionally you can exchange #PB_Date_Access with #PB_Date_Modified or #PB_Date_Created to get the possible dates on windows.

Re: File modification date

Posted: Sat Jun 29, 2024 5:24 pm
by jak64
Thank you Marc56us

Re: File modification date

Posted: Sun Jun 30, 2024 1:14 am
by electrochrisso

Code: Select all

Debug FormatDate("%dd/%mm/%yyyy - %hh:%ii:%ss", GetFileDate("C:\DumpStack.log",#PB_Date_Created))
Debug FormatDate("%dd/%mm/%yyyy - %hh:%ii:%ss", GetFileDate("C:\DumpStack.log",#PB_Date_Accessed))
Debug FormatDate("%dd/%mm/%yyyy - %hh:%ii:%ss", GetFileDate("C:\DumpStack.log",#PB_Date_Modified))
I get output of 1 hour earlier on accessed and modified, might be something to do with daylight saving time setting?

Re: File modification date

Posted: Tue Jul 02, 2024 10:45 am
by jak64
Hello electrochrisso
I tried with another file (A song) and I have the correct time, despite summer time here in France. There is no one or two hour lag.
I am in PureBasic Version 6.10 Windows 11 64-bit Professional

Re: File modification date

Posted: Tue Jul 02, 2024 11:34 am
by Marc56us
:!: DST (daylight saving time) only takes into account the summer/winter time difference (if used), not the time zone difference, so never more than one hour.
There may also be a time difference between file systems, depending on how a server (e.g. Samba) and Windows clients are configured. Some backup/sync programs have an option to handle this.
:wink:

Re: File modification date

Posted: Fri Jul 05, 2024 4:08 am
by electrochrisso
After checking things out, it depends on the daylight saving setting and when the file date time was created/changed, e.g. if the file date was created/changed in winter and checked in summer or visa versa, their will be an hours difference, so this could be something to think about when creating a program that needs accurate time information from file dates.

Re: File modification date

Posted: Fri Jul 05, 2024 11:38 am
by Axolotl
On that regard,

I found some interessting information about DST and file storage.....
While NTFS records all times in UTC, other file systems such as FAT and FAT32 record file times in local time. This impacts your ability to consistently retrieve the file's modified date.
So if you are talking about file times on an NTFS volume, then you're fine. But if you're talking about file times on a FAT32 volume (perhaps from a USB thumbdrive or a camera's SD card) then you are not guaranteed accurate conversion. This is a good reason to format your SD cards using exFAT instead of FAT32, since exFAT includes a time zone offset, which allows for accurate conversion back to UTC.

Probably you find detailed information about DST, UTC and so on at:
Microsoft...handle-dates-and-times-dst
FileTimeToLocalFileTime_()
LocalFileTimeToFileTime_()

Re: File modification date

Posted: Sat Jul 06, 2024 12:39 am
by electrochrisso
Some more useful info to think about Axolotl :)

Re: File modification date

Posted: Sat Jul 06, 2024 7:53 am
by mk-soft