func Join(paths ...string) string
func ExampleJoin() {
// init
var (
dirPath = gfile.TempDir("gfile_example_basic_dir")
filePath = "file1"
)
// Joins string array paths with file separator of current system.
joinString := gfile.Join(dirPath, filePath)
fmt.Println(joinString)
// Output:
// /tmp/gfile_example_basic_dir/file1
}
func Abs(path string) string
func ExampleAbs() {
// init
var (
path = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
)
// Get an absolute representation of path.
fmt.Println(gfile.Abs(path))
// Output:
// /tmp/gfile_example_basic_dir/file1
}
func RealPath(path string) string
func ExampleRealPath() {
// init
var (
realPath = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
worryPath = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "worryFile")
)
// fetch an absolute representation of path.
fmt.Println(gfile.RealPath(realPath))
fmt.Println(gfile.RealPath(worryPath))
// Output:
// /tmp/gfile_example_basic_dir/file1
//
}
func SelfName() string
func ExampleSelfName() {
// Get file name of current running process
fmt.Println(gfile.SelfName())
// May Output:
// ___github_com_GOgf_gf_v2_os_gfile__ExampleSelfName
}
func Basename(path string) string
func ExampleBasename() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
)
// Get the last element of path, which contains file extension.
fmt.Println(gfile.Basename(path))
// Output:
// file.log
}
func Name(path string) string
func ExampleName() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
)
// Get the last element of path without file extension.
fmt.Println(gfile.Name(path))
// Output:
// file
}
func Dir(path string) string
func ExampleDir() {
// init
var (
path = gfile.Join(gfile.TempDir("gfile_example_basic_dir"), "file1")
)
// Get all but the last element of path, typically the path's directory.
fmt.Println(gfile.Dir(path))
// Output:
// /tmp/gfile_example_basic_dir
}
func Ext(path string) string
func ExampleExt() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
)
// Get the file name extension used by path.
fmt.Println(gfile.Ext(path))
// Output:
// .log
}
func ExtName(path string) string
func ExampleExtName() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
)
// Get the file name extension used by path but the result does not contains symbol '.'.
fmt.Println(gfile.ExtName(path))
// Output:
// log
}
func MainPkgPath() string
func Test() {
fmt.Println("main pkg path on main :", gfile.MainPkgPath())
char := make(chan int, 1)
go func() {
fmt.Println("main pkg path on goroutine :", gfile.MainPkgPath())
char <- 1
}()
select {
case <-char:
}
// Output:
// /xxx/xx/xxx/xx
// /xxx/xx/xxx/xx
}
// 二进制包
$ ./testDemo
main pkg path on main : /xxx/xx/xxx/xx
main pkg path on goroutine : /xxx/xx/xxx/xx
网站栏目:创新互联GoFrame教程:GoFramegfile-路径操作
转载源于:http://www.shufengxianlan.com/qtweb/news41/331941.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联