GoFrame gfile-类型判断

2022-04-09 11:32 更新

类型判断

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
}


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号