Page 1 of 1

Bad file date with FAT32

Posted: Wed May 08, 2024 9:55 am
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

Re: Bad file date with FAT32

Posted: Wed May 08, 2024 10:14 am
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.

Re: Bad file date with FAT32

Posted: Wed May 08, 2024 10:17 am
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

Re: Bad file date with FAT32

Posted: Wed May 08, 2024 12:22 pm
by LavaKri
Sorry for this topic, it's exact.
I have the same date resolution if i copy with window file explorer.

Thank's