本文整理汇总了Golang中golang.org/x/tools/godoc/vfs.FileSystem.ReadDir方法的典型用法代码示例。如果您正苦于以下问题:Golang FileSystem.ReadDir方法的具体用法?Golang FileSystem.ReadDir怎么用?Golang FileSystem.ReadDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/tools/godoc/vfs.FileSystem
的用法示例。
在下文中一共展示了FileSystem.ReadDir方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: glob
// glob searches for files matching pattern in the directory dir
// and appends them to matches. If the directory cannot be
// opened, it returns the existing matches. New matches are
// added in lexicographical order.
func glob(fs vfs.FileSystem, dir, pattern string, matches []string) (m []string, e error) {
m = matches
fi, err := fs.Stat(dir)
if err != nil {
return
}
if !fi.IsDir() {
return
}
fis, err := fs.ReadDir(dir)
if err != nil {
return
}
sort.Sort(byName(fis))
for _, fi := range fis {
n := fi.Name()
matched, err := path.Match(path.Clean(pattern), n)
if err != nil {
return m, err
}
if matched {
m = append(m, path.Join(dir, n))
}
}
return
}
示例2: readDirNames
// readDirNames reads the directory named by dirname and returns
// a sorted list of directory entries.
func readDirNames(fs vfs.FileSystem, dirname string) ([]string, error) {
fis, err := fs.ReadDir(dirname)
if err != nil {
return nil, err
}
names := make([]string, len(fis))
for i := range fis {
names[i] = fis[i].Name()
}
sort.Strings(names)
return names, nil
}
示例3: readDirNames
// readDirNames reads the directory named by dirname and returns
// a sorted list of directory entries.
func readDirNames(fs vfs.FileSystem, dirname string) ([]string, error) {
dirname = filepath.ToSlash(dirname)
fileInfoList, err := fs.ReadDir(dirname)
if err != nil {
return nil, err
}
var names []string
for _, fi := range fileInfoList {
names = append(names, fi.Name())
}
sort.Strings(names)
return names, nil
}
示例4: readDir
// readDir uses the passed vfs.FileSystem to read from starting at the base path.
// If recurseSingleSubfolder is true, it will descend and include sub-folders
// with a single sub-folder inside. first should always be set to true, other values are used internally.
func readDir(fs vfs.FileSystem, base string, recurseSingleSubfolder bool, first bool) ([]*TreeEntry, error) {
entries, err := fs.ReadDir(base)
if err != nil {
return nil, err
}
if recurseSingleSubfolder && !first && !singleSubDir(entries) {
return nil, nil
}
te := make([]*TreeEntry, len(entries))
for i, fi := range entries {
te[i] = newTreeEntry(fi)
if fi.Mode().IsDir() && recurseSingleSubfolder {
ee, err := readDir(fs, path.Join(base, fi.Name()), recurseSingleSubfolder, false)
if err != nil {
return nil, err
}
te[i].Entries = ee
}
}
return te, nil
}