当前位置: 首页>>代码示例>>Golang>>正文


Golang FileSystem.ReadDir方法代码示例

本文整理汇总了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
}
开发者ID:wutaizeng,项目名称:kapacitor,代码行数:32,代码来源:match.go

示例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
}
开发者ID:wutaizeng,项目名称:kapacitor,代码行数:14,代码来源:walk.go

示例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
}
开发者ID:iolg,项目名称:golangdoc,代码行数:15,代码来源:walk.go

示例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
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:24,代码来源:fs.go


注:本文中的golang.org/x/tools/godoc/vfs.FileSystem.ReadDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。