I was hoping to find the created date of a file in Windows. How would I be able to accomplish this simply?
I have been using os.Stat
and os.Chtimes
to get other file information but it does not seem to offer information on created date.
The FileInfo.Sys
method returns the system specific data structures. On Windows, this will be a syscall.Win32FileAttributeData
, which looks like
type Win32FileAttributeData struct {
FileAttributes uint32
CreationTime Filetime
LastAccessTime Filetime
LastWriteTime Filetime
FileSizeHigh uint32
FileSizeLow uint32
}
Getting the creation time would look something like:
d := fi.Sys().(*syscall.Win32FileAttributeData)
cTime = time.Unix(0, d.CreationTime.Nanoseconds())
Since this is windows specific, this of course should be protected by build constraints. Either using a _windows.go
file or // +build windows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With