File modification date

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

File modification date

Post 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
Axolotl
Addict
Addict
Posts: 841
Joined: Wed Dec 31, 2008 3:36 pm

Re: File modification date

Post 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
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: File modification date

Post 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:
Comfort
User
User
Posts: 32
Joined: Thu Jul 05, 2018 11:52 pm

Re: File modification date

Post by Comfort »

That be the ExamineDirectory() example.
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: File modification date

Post 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
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: File modification date

Post 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)
Axolotl
Addict
Addict
Posts: 841
Joined: Wed Dec 31, 2008 3:36 pm

Re: File modification date

Post 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.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: File modification date

Post by jak64 »

Thank you Marc56us
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: File modification date

Post 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?
PureBasic! Purely the best 8)
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: File modification date

Post 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
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: File modification date

Post 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:
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: File modification date

Post 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.
PureBasic! Purely the best 8)
Axolotl
Addict
Addict
Posts: 841
Joined: Wed Dec 31, 2008 3:36 pm

Re: File modification date

Post 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_()
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: File modification date

Post by electrochrisso »

Some more useful info to think about Axolotl :)
PureBasic! Purely the best 8)
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: File modification date

Post by mk-soft »

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply