gitee.com/quant1x/gox@v1.21.2/api/filestat_windows.go (about)

     1  //go:build windows
     2  
     3  package api
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  )
     9  
    10  // GetFileStat 获取文件状态(创建,修改和访问时间)
    11  func GetFileStat(name string) (*FileStat, error) {
    12  	finfo, err := os.Lstat(name)
    13  	if err != nil {
    14  		return nil, err
    15  	}
    16  	// windows下代码如下
    17  	fileAttr, ok := finfo.Sys().(*syscall.Win32FileAttributeData)
    18  	if !ok || fileAttr == nil {
    19  		return nil, ErrInvalidFileStat
    20  	}
    21  	return &FileStat{
    22  		CreationTime:   NanosecondToTime(fileAttr.CreationTime.Nanoseconds()),
    23  		LastAccessTime: NanosecondToTime(fileAttr.LastAccessTime.Nanoseconds()),
    24  		LastWriteTime:  NanosecondToTime(fileAttr.LastWriteTime.Nanoseconds()),
    25  	}, nil
    26  }