windows.go 805 B

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