func ScanDir(path string, pattern string, recursive ...bool) ([]string, error)
func ExampleScanDir() {
// init
var (
fileName = "gflie_example.txt"
tempDir = gfile.TempDir("gfile_example_scan_dir")
tempFile = gfile.Join(tempDir, fileName)
tempSubDir = gfile.Join(tempDir, "sub_dir")
tempSubFile = gfile.Join(tempSubDir, fileName)
)
// write contents
gfile.PutContents(tempFile, "goframe example content")
gfile.PutContents(tempSubFile, "goframe example content")
// scans directory recursively
list, _ := gfile.ScanDir(tempDir, "*", true)
for _, v := range list {
fmt.Println(gfile.Basename(v))
}
// Output:
// gflie_example.txt
// sub_dir
// gflie_example.txt
}
func ScanDirFile(path string, pattern string, recursive ...bool) ([]string, error)
func ExampleScanDirFile() {
// init
var (
fileName = "gflie_example.txt"
tempDir = gfile.TempDir("gfile_example_scan_dir_file")
tempFile = gfile.Join(tempDir, fileName)
tempSubDir = gfile.Join(tempDir, "sub_dir")
tempSubFile = gfile.Join(tempSubDir, fileName)
)
// write contents
gfile.PutContents(tempFile, "goframe example content")
gfile.PutContents(tempSubFile, "goframe example content")
// scans directory recursively exclusive of directories
list, _ := gfile.ScanDirFile(tempDir, "*.txt", true)
for _, v := range list {
fmt.Println(gfile.Basename(v))
}
// Output:
// gflie_example.txt
// gflie_example.txt
}
func ScanDirFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
func ExampleScanDirFunc() {
// init
var (
fileName = "gflie_example.txt"
tempDir = gfile.TempDir("gfile_example_scan_dir_func")
tempFile = gfile.Join(tempDir, fileName)
tempSubDir = gfile.Join(tempDir, "sub_dir")
tempSubFile = gfile.Join(tempSubDir, fileName)
)
// write contents
gfile.PutContents(tempFile, "goframe example content")
gfile.PutContents(tempSubFile, "goframe example content")
// scans directory recursively
list, _ := gfile.ScanDirFunc(tempDir, "*", true, func(path string) string {
// ignores some files
if gfile.Basename(path) == "gflie_example.txt" {
return ""
}
return path
})
for _, v := range list {
fmt.Println(gfile.Basename(v))
}
// Output:
// sub_dir
}
func ScanDirFileFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
func ExampleScanDirFileFunc() {
// init
var (
fileName = "gflie_example.txt"
tempDir = gfile.TempDir("gfile_example_scan_dir_file_func")
tempFile = gfile.Join(tempDir, fileName)
fileName1 = "gflie_example_ignores.txt"
tempFile1 = gfile.Join(tempDir, fileName1)
tempSubDir = gfile.Join(tempDir, "sub_dir")
tempSubFile = gfile.Join(tempSubDir, fileName)
)
// write contents
gfile.PutContents(tempFile, "goframe example content")
gfile.PutContents(tempFile1, "goframe example content")
gfile.PutContents(tempSubFile, "goframe example content")
// scans directory recursively exclusive of directories
list, _ := gfile.ScanDirFileFunc(tempDir, "*.txt", true, func(path string) string {
// ignores some files
if gfile.Basename(path) == "gflie_example_ignores.txt" {
return ""
}
return path
})
for _, v := range list {
fmt.Println(gfile.Basename(v))
}
// Output:
// gflie_example.txt
// gflie_example.txt
}
备案信息: 粤ICP备15087711号-2
Copyright © 2008-2024 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。