Bad file date with FAT32

Just starting out? Need help? Post your questions and find answers here.
LavaKri
New User
New User
Posts: 2
Joined: Wed May 08, 2024 8:44 am

Bad file date with FAT32

Post by LavaKri »

Hi,
i'm coding a tool to save some files on a USBKey, generaly formated in FAT32.
But CopyFile() and SetFileDate() don't write correctlye the modified date of files.

Code: Select all

EnableExplicit
Global USBVolume$ = "G:\" 
Global File$ = USBVolume$ + "Test.txt"
CreateFile(0, File$)
CloseFile(0)

Global date.q = Date(2024, 05, 06, 10, 01,11)
SetFileDate(File$, #PB_Date_Created, Date)
SetFileDate(File$, #PB_Date_Modified, Date)
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss", Date)
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss Created", GetFileDate(File$, #PB_Date_Created))
Debug FormatDate("%yyyy/%mm/%dd    %hh:%ii:%ss Modified", GetFileDate(File$, #PB_Date_Modified))
RunProgram(USBVolume$ )
With a USBVolume formated in NTFS the dates have the same value.
but on FAT32 i have this results :

Code: Select all

2024/05/06    10:01:11
2024/05/06    10:01:11 Created
2024/05/06    10:01:12 Modified	
One or two seconds are added to the modified date ...

Thank's
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Bad file date with FAT32

Post by Kiffi »

I would say this is to be expected as USB drives are relatively slow. For this reason, I don't think it's a PB bug.
Hygge
PeDe
Enthusiast
Enthusiast
Posts: 305
Joined: Sun Nov 26, 2017 3:13 pm

Re: Bad file date with FAT32

Post by PeDe »

The modification date is rounded to even seconds.

Quote from the SDK Windows Help:

Code: Select all

SetFileTime function

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 SetFileTime. NTFS delays updates to the last access time for a file by up to
one hour after the last access.
Peter
LavaKri
New User
New User
Posts: 2
Joined: Wed May 08, 2024 8:44 am

Re: Bad file date with FAT32

Post by LavaKri »

Sorry for this topic, it's exact.
I have the same date resolution if i copy with window file explorer.

Thank's
Post Reply