本文整理汇总了Golang中github.com/colinmarc/hdfs.Client.ReadDir方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.ReadDir方法的具体用法?Golang Client.ReadDir怎么用?Golang Client.ReadDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/colinmarc/hdfs.Client
的用法示例。
在下文中一共展示了Client.ReadDir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: expandGlobs
// expandGlobs recursively expands globs in a filepath. It assumes the paths
// are already cleaned and normalize (ie, absolute).
func expandGlobs(client *hdfs.Client, globbedPath string) ([]string, error) {
parts := strings.Split(globbedPath, "/")[1:]
var res []string
var splitAt int
for splitAt = range parts {
if hasGlob(parts[splitAt]) {
break
}
}
var base, glob, next, remainder string
base = "/" + path.Join(parts[:splitAt]...)
glob = parts[splitAt]
if len(parts) > splitAt+1 {
next = parts[splitAt+1]
remainder = path.Join(parts[splitAt+2:]...)
} else {
next = ""
remainder = ""
}
list, err := client.ReadDir(base)
if err != nil {
return nil, err
}
for _, fi := range list {
match, _ := path.Match(glob, fi.Name())
if !match {
continue
}
if !hasGlob(next) {
_, err := client.Stat(path.Join(base, fi.Name(), next))
if err != nil && !os.IsNotExist(err) {
return nil, err
} else if os.IsNotExist(err) {
continue
}
}
newPath := path.Join(base, fi.Name(), next, remainder)
if hasGlob(newPath) {
children, err := expandGlobs(client, newPath)
if err != nil {
return nil, err
}
res = append(res, children...)
} else {
res = append(res, newPath)
}
}
return res, nil
}
示例2: RecurseInfos
func RecurseInfos(hdfsClient *hdfs.Client, hdfsDir string) ([]HadoopFile, error) {
hdfsFiles := make([]HadoopFile, 0)
dirs, err := hdfsClient.ReadDir(hdfsDir)
if err != nil {
return nil, err
}
for _, fileInfo := range dirs {
if fileInfo.IsDir() {
recurseInfos, err := RecurseInfos(hdfsClient, hdfsDir+fileInfo.Name()+"/")
if err != nil {
return nil, err
}
for _, f := range recurseInfos {
hdfsFiles = append(hdfsFiles, f)
}
} else {
f := HadoopFile{dirPrefix: hdfsDir, fileInfo: fileInfo}
hdfsFiles = append(hdfsFiles, f)
}
}
return hdfsFiles, nil
}