GoFrame gfile-常用目录

常用目录

Pwd

  • 说明:获取当前工作路径。
  • 格式: 
func Pwd() string
  • 示例:
func ExamplePwd() {
	// Get absolute path of current working directory.
	fmt.Println(gfile.Pwd())

	// May Output:
	// xxx/gf/os/gfile
}

Home

  • 说明:获取运行用户的主目录
  • 格式: 
func Home(names ...string) (string, error) 
  • 示例:
func ExampleHome() {
	// users home directory
	homePath, _ := gfile.Home()
	fmt.Println(homePath)

	// May Output:
	// C:Usershailaz
}

TempDir

  • 说明:获取拼接系统临时路径后的绝对地址。
  • 格式: 
func TempDir(names ...string) string
  • 示例:
func ExampleTempDir() {
	// init
	var (
		fileName = "gfile_example_basic_dir"
	)

	// fetch an absolute representation of path.
	path := gfile.TempDir(fileName)

	fmt.Println(path)

	// Output:
	// /tmp/gfile_example_basic_dir
}

SelfPath

  • 说明:获取当前运行程序的绝对路径。
  • 格式: 
func SelfPath() string 
  • 示例:
func ExampleSelfPath() {

	// Get absolute file path of current running process
	fmt.Println(gfile.SelfPath())

	// May Output:
	// xxx/___github_com_gogf_gf_v2_os_gfile__ExampleSelfPath
}

作者:andy,如若转载,请注明出处:https://www.web176.com/goframe/20935.html

(0)
打赏 支付宝 支付宝 微信 微信
andy的头像andy
上一篇 2023年5月18日
下一篇 2023年5月18日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注