Last active
May 11, 2017 03:41
-
-
Save piaoger/1a1cc29fa9fe95695282e2f5c57ec221 to your computer and use it in GitHub Desktop.
get/set filetime in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"os" | |
"syscall" | |
"time" | |
) | |
func statTimes(name string) (atime, mtime, ctime time.Time, err error) { | |
fi, err := os.Stat(name) | |
if err != nil { | |
return | |
} | |
mtime = fi.ModTime() | |
stat := fi.Sys().(*syscall.Stat_t) | |
atime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) | |
ctime = time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec)) | |
return | |
} | |
func chTimes(name string, atime time.Time, mtime time.Time) { | |
os.Chtimes(name, atime, mtime) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment