GoFrame gfile-權(quán)限操作

2022-04-09 11:35 更新

權(quán)限操作

IsReadable

  • 說明:檢查給定的路徑是否可讀。
  • 格式: 

func IsReadable(path string) bool 

  • 示例:

func ExampleIsReadable() {
	// init
	var (
		path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
	)

	// Checks whether given `path` is readable.
	fmt.Println(gfile.IsReadable(path))

	// Output:
	// true
}

IsWritable

  • 說明:檢查指定路徑是否可寫,如果路徑是目錄,則會創(chuàng)建臨時文件檢查是否可寫,如果是文件則判斷是否可以打開
  • 格式: 

func IsWritable(path string) bool 

  • 示例:

func ExampleIsWritable() {
	// init
	var (
		path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
	)

	// Checks whether given `path` is writable.
	fmt.Println(gfile.IsWritable(path))

	// Output:
	// true
}

Chmod

  • 說明:使用指定的權(quán)限,更改指定路徑的文件權(quán)限。
  • 格式: 

func Chmod(path string, mode os.FileMode) error

  • 類型:

func ExampleChmod() {
	// init
	var (
		path = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
	)

	// Get a FileInfo describing the named file.
	stat, err := gfile.Stat(path)
	if err != nil {
		fmt.Println(err.Error())
	}
	// Show original mode
	fmt.Println(stat.Mode())

	// Change file model
	gfile.Chmod(path, gfile.DefaultPermCopy)

	// Get a FileInfo describing the named file.
	stat, _ = gfile.Stat(path)
	// Show the modified mode
	fmt.Println(stat.Mode())

	// Output:
	// -rw-r--r--
	// -rwxrwxrwx
}


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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號