GoFrame gfile-常用目录

2022-04-09 11:29 更新

常用目录

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() {
	// user's home directory
	homePath, _ := gfile.Home()
	fmt.Println(homePath)

	// May Output:
	// C:\Users\hailaz
}

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
}


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

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号