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
}


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號