github.com/PandaGoAdmin/utils@v0.0.0-20211208134815-d5461603a00f/file_windows.go (about) 1 // +build windows 2 3 package kgo 4 5 import ( 6 "os" 7 "path/filepath" 8 "strings" 9 ) 10 11 // IsReadable 路径是否可读. 12 func (kf *LkkFile) IsReadable(fpath string) (res bool) { 13 info, err := os.Stat(fpath) 14 15 if err != nil { 16 return 17 } 18 19 if info.Mode().Perm()&(1<<(uint(8))) == 0 { 20 return 21 } 22 23 res = true 24 return 25 } 26 27 // IsWritable 路径是否可写. 28 func (kf *LkkFile) IsWritable(fpath string) (res bool) { 29 info, err := os.Stat(fpath) 30 31 if err != nil { 32 return 33 } 34 35 if info.Mode().Perm()&(1<<(uint(7))) == 0 { 36 return 37 } 38 39 res = true 40 return 41 } 42 43 // IsExecutable 是否可执行文件. 44 func (kf *LkkFile) IsExecutable(fpath string) bool { 45 info, err := os.Stat(fpath) 46 return err == nil && info.Mode().IsRegular() && (info.Mode()&0111) != 0 47 } 48 49 // FormatPath 格式化路径. 50 func (kf *LkkFile) FormatPath(fpath string) string { 51 if fpath == "" { 52 return "" 53 } 54 55 fpath = formatPath(fpath) 56 dir := formatPath(filepath.Dir(fpath)) 57 58 if dir == `.` { 59 return fpath 60 } 61 62 return strings.TrimRight(dir, "/") + "/" + filepath.Base(fpath) 63 }