windows.go 733 B

12345678910111213141516171819202122232425262728293031
  1. //go:build windows
  2. package get_access_time
  3. import (
  4. "os"
  5. "syscall"
  6. "time"
  7. )
  8. type OneGetAccessTime struct {
  9. }
  10. func (d OneGetAccessTime) GetOSName() string {
  11. return "windows"
  12. }
  13. func (d OneGetAccessTime) GetAccessTime(fileName string) (time.Time, error) {
  14. // return now time and err if file does not exist
  15. fi, err := os.Stat(fileName)
  16. if os.IsNotExist(err) {
  17. return time.Now(), err
  18. }
  19. // get last access time for different platform
  20. // https://studygolang.com/topics/6270
  21. // https://github.com/golang/go/commit/bd75468a089c8ad38bcb1130c4ed7d2703ef85c1
  22. // https://github.com/golang/go/issues/31735
  23. aTime := fi.Sys().(*syscall.Win32FileAttributeData).LastAccessTime
  24. return time.Unix(aTime.Nanoseconds()/1e9, 0), nil
  25. }