-
Notifications
You must be signed in to change notification settings - Fork 58
/
file_windows.go
47 lines (35 loc) · 942 Bytes
/
file_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//go:build windows
// +build windows
package kgo
import (
"os"
"path/filepath"
"strings"
)
// IsReadable 路径是否可读.
func (kf *LkkFile) IsReadable(fpath string) bool {
info, err := os.Stat(fpath)
return err == nil && info.Mode().Perm()&(1<<(uint(8))) != 0
}
// IsWritable 路径是否可写.
func (kf *LkkFile) IsWritable(fpath string) bool {
info, err := os.Stat(fpath)
return err == nil && info.Mode().Perm()&(1<<(uint(7))) != 0
}
// IsExecutable 是否可执行文件.
func (kf *LkkFile) IsExecutable(fpath string) bool {
info, err := os.Stat(fpath)
return err == nil && info.Mode().IsRegular() && (info.Mode()&0111) != 0
}
// FormatPath 格式化路径.
func (kf *LkkFile) FormatPath(fpath string) string {
if fpath == "" {
return ""
}
fpath = formatPath(fpath)
dir := formatPath(filepath.Dir(fpath))
if dir == `.` {
return fpath
}
return strings.TrimRight(dir, "/") + "/" + filepath.Base(fpath)
}