GoFrame gfile-权限操作

权限操作

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

  • 说明:检查指定路径是否可写,如果路径是目录,则会创建临时文件检查是否可写,如果是文件则判断是否可以打开
  • 格式: 
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

  • 说明:使用指定的权限,更改指定路径的文件权限。
  • 格式: 
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
}

作者:唐伯虎点蚊香,如若转载,请注明出处:https://www.web176.com/goframe/20933.html

(0)
打赏 支付宝 支付宝 微信 微信
唐伯虎点蚊香的头像唐伯虎点蚊香
上一篇 2023年5月18日 下午3:47
下一篇 2023年5月18日 下午3:47

相关推荐

发表回复

登录后才能评论