Skip to content

Instantly share code, notes, and snippets.

@ba0f3
Created February 26, 2021 17:54
Show Gist options
  • Save ba0f3/f3523c095697a3607abc0579b988c14a to your computer and use it in GitHub Desktop.
Save ba0f3/f3523c095697a3607abc0579b988c14a to your computer and use it in GitHub Desktop.
Get FILETIME and convert posix time to windows FILENAME
const EPOCH_DIFF = 11644473600'i64
type FILETIME = object
dwLowDateTime: uint32
dwHighDateTime: uint32
proc toFileTime(tv: Timeval): FILETIME =
var mtime = EPOCH_DIFF + tv.tv_sec.int64
mtime = mtime + tv.tv_usec * 10;
mtime = mtime * 10_000_000
result = cast[FILETIME](mtime)
proc getLastWriteTime(file: string): FILETIME =
var
res: Stat
tv: Timeval
if stat(filename, res) < 0'i32: raiseOSError(osLastError(), file)
tv.tv_sec = res.st_mtime
result = toFileTime(tv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment