Get the UTC modification date of a file
Posted: Tue Aug 06, 2024 12:38 pm
I found two options, but I get different results. Why?
Code: Select all
filename$ = "c:\Program Files\PureBasic\Examples\Sources\Data\Background.bmp"
Structure stats
size.q
mtim.q
ctim.q
EndStructure
; ================================================
Procedure GetFileStats1(filename.s, *stats.stats)
*stats\mtim = ConvertDate(GetFileDate(filename, #PB_Date_Modified), #PB_Date_UTC)
*stats\ctim = ConvertDate(GetFileDate(filename, #PB_Date_Created ), #PB_Date_UTC)
*stats\size = FileSize(filename)
EndProcedure
Define test1.stats
GetFileStats1(filename$, test1)
Debug test1\mtim
; ================================================
Structure stat64 Align #PB_Structure_AlignC
st_dev.l ; ID of device containing the file
st_ino.u ; Serial number for the file
st_mode.u ; Access mode and file type for the file
st_nlink.w ; Number of links to the file
st_uid.w ; User ID of file owner
st_gid.w ; Group ID of group owner
st_rdev.l ; Device ID (if the file is a character or block special device)
st_size.q ; File size in bytes (if the file is a regular file)
st_atime.q ; Time of last access
st_mtime.q ; Time of last data modification
st_ctime.q ; Time of last file status change
EndStructure
ImportC ""
_stat64(path.p-utf8, *buf)
EndImport
Procedure GetFileStats2(filename.s, *stats.stats): Protected stat64.stat64
_stat64(filename, stat64)
*stats\mtim = stat64\st_mtime ; UTC-Time Modified
*stats\ctim = stat64\st_ctime ; UTC-Time Created/Birth
*stats\size = stat64\st_size
EndProcedure
Define test2.stats
GetFileStats2(filename$, test2)
Debug test2\mtim
1606217524
1606213924
