You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
680 B
Go
33 lines
680 B
Go
5 years ago
|
package staros
|
||
|
|
||
|
import "os"
|
||
|
|
||
|
// 检测文件/文件夹是否存在
|
||
|
func Exists(path string) bool {
|
||
|
_, err := os.Stat(path)
|
||
|
if err != nil && os.IsNotExist(err) {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
|
||
|
// IsFile 返回给定文件地址是否是一个文件,
|
||
|
//True为是一个文件,False为不是文件或路径无效
|
||
|
func IsFile(fpath string) bool {
|
||
|
s, err := os.Stat(fpath)
|
||
|
if err != nil {
|
||
|
return false
|
||
|
}
|
||
|
return !s.IsDir()
|
||
|
}
|
||
|
|
||
|
// IsFolder 返回给定文件地址是否是一个文件夹,
|
||
|
//True为是一个文件夹,False为不是文件夹或路径无效
|
||
|
func IsFolder(fpath string) bool {
|
||
|
s, err := os.Stat(fpath)
|
||
|
if err != nil {
|
||
|
return false
|
||
|
}
|
||
|
return s.IsDir()
|
||
|
}
|