后浪云GoFrame教程:GoFrame gfile-类型判断
类型判断
IsDir
- 说明:检查给定的路径是否是文件夹。
- 格式:
func IsDir(path string) bool
- 示例:
func ExampleIsDir() {
// init
var (
path = gfile.TempDir("gfile_example_basic_dir")
filePath = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
)
// Checks whether given `path` a directory.
fmt.Println(gfile.IsDir(path))
fmt.Println(gfile.IsDir(filePath))
// Output:
// true
// false
}
IsFile
- 说明:检查给定的路径是否是文件。
- 格式:
func IsFile(path string) bool
- 示例:
func ExampleIsFile() {
// init
var (
filePath = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
dirPath = gfile.TempDir("gfile_example_basic_dir")
)
// Checks whether given `path` a file, which means it's not a directory.
fmt.Println(gfile.IsFile(filePath))
fmt.Println(gfile.IsFile(dirPath))
// Output:
// true
// false
}
版权声明:
作者:后浪云
链接:https://www.idc.net/help/192891/
文章版权归作者所有,未经允许请勿转载。
THE END