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


Golang File.Readdirnames方法代码示例

本文整理汇总了Golang中os.File.Readdirnames方法的典型用法代码示例。如果您正苦于以下问题:Golang File.Readdirnames方法的具体用法?Golang File.Readdirnames怎么用?Golang File.Readdirnames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os.File的用法示例。


在下文中一共展示了File.Readdirnames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetPending

func (ck *CertKit) GetPending() (map[string]interface{}, error) {
	var err error
	var resp map[string]interface{}
	var names []string
	var fh *os.File
	var buf []byte

	resp = map[string]interface{}{}

	fh, err = os.Open(fmt.Sprintf("%s%cpending", ck.Path, os.PathSeparator))
	if err != nil {
		Goose.Auth.Logf(1, "Error opening pending directory (%s%cpending): %s", ck.Path, os.PathSeparator, err)
		return nil, err
	}

	names, err = fh.Readdirnames(-1)
	if err != nil {
		Goose.Auth.Logf(1, "Error reading pending directory (%s%cpending): %s", ck.Path, os.PathSeparator, err)
		return nil, err
	}

	for _, k := range names {
		if (len(k) > 4) && (k[len(k)-4:] == ".crt") {
			buf, err = ioutil.ReadFile(fmt.Sprintf("%s%cpending%c%s", ck.Path, os.PathSeparator, os.PathSeparator, k))
			if err != nil {
				Goose.Auth.Logf(1, "Error reading pending certificate (%s%cpending%c%s): %s", ck.Path, os.PathSeparator, os.PathSeparator, k, err)
				return nil, err
			}
			resp[k[:len(k)-4]] = string(buf)
		}
	}

	return resp, nil
}
开发者ID:luisfurquim,项目名称:stonelizard,代码行数:34,代码来源:auth.go

示例2: Open

func (w *World) Open(dir string) (err error) {
	var fd *os.File

	w.dir = dir + "/o/"
	fd, err = os.Open(w.dir)
	if err == nil {
		defer fd.Close()
		var names []string
		names, err = fd.Readdirnames(0)
		if err == nil {
			w.obj = make(map[oid]*Obj, len(names))
			for _, name := range names {
				var id oid

				if id, err = strid(name); err == nil {
					_, err = w.Load(id)
				}
				if err != nil {
					break
				}
			}
		}
	}
	return
}
开发者ID:nikitadanilov,项目名称:alp,代码行数:25,代码来源:world.go

示例3: listAllUsers

func listAllUsers(dir *os.File, list UserListFull) error {
	for {
		last := false
		names, err := dir.Readdirnames(3)
		if err != nil {
			if err == io.EOF {
				last = true
			} else {
				return err
			}
		}

		for _, name := range names {
			var user UserFull
			var err error
			var username string
			if user.IsValid, username, user.IsAdmin, err = checkUserFile(name); err != nil {
				return err
			}
			user.IsSupported, user.FormatID, user.LastChanged, user.FormatParams, _ = isFormatSupportedFull(filepath.Join(dir.Name(), name))
			list[username] = user
		}

		if last {
			break
		}
	}
	return nil
}
开发者ID:whawty,项目名称:auth,代码行数:29,代码来源:store.go

示例4: filterTheme

func filterTheme(dir string, conditions []string) bool {
	var err error

	var f *os.File
	if f, err = os.Open(dir); err != nil {
		logger.Debugf("Open '%s' failed: %v", dir, err)
		return false
	}
	defer f.Close()

	names := []string{}
	if names, err = f.Readdirnames(0); err != nil {
		logger.Debugf("Readdirnames '%s' failed: %v", dir, err)
		return false
	}

	cnt := 0
	for _, name := range names {
		for _, c := range conditions {
			if name == c {
				cnt++
				break
			}
		}
	}

	if cnt == len(conditions) {
		return true
	}

	return false
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:32,代码来源:list.go

示例5: addtozip

func addtozip(z *zip.Writer, name string, f *os.File) {

	if fi, _ := f.Stat(); fi.IsDir() {
		log.Println("Adding folder", name)
		names, _ := f.Readdirnames(-1)
		for _, subname := range names {
			file, err := os.Open(filepath.Join(f.Name(), subname))
			if err != nil {
				log.Println(err)
				continue
			}
			addtozip(z, filepath.Join(name, subname), file)
			file.Close()
		}
	} else {
		log.Println("Adding file", name)
		fw, err := z.Create(name)
		if err != nil {
			panic(err)
		}
		_, err = io.Copy(fw, f)
		if err != nil {
			panic(err)
		}
	}
}
开发者ID:HeinOldewage,项目名称:Hyades,代码行数:26,代码来源:ziphelper.go

示例6: GetAllAttachments

func (self articleStore) GetAllAttachments() (names []string, err error) {
	var f *os.File
	f, err = os.Open(self.attachments)
	if err == nil {
		names, err = f.Readdirnames(0)
	}
	return
}
开发者ID:kurtcoke,项目名称:srndv2,代码行数:8,代码来源:store.go

示例7: Scan

// Scan walks the directory tree at dir, looking for source units that match profiles in the
// configuration. Scan returns a list of all source units found.
func (c Config) Scan(dir string) (found []Unit, err error) {
	var profiles []Profile
	if c.Profiles != nil {
		profiles = c.Profiles
	} else {
		profiles = AllProfiles
	}

	c.Base, _ = filepath.Abs(c.Base)

	skipFiles := false
	for _, profile := range profiles {
		err = filepath.Walk(dir, func(path string, info os.FileInfo, inerr error) (err error) {
			if inerr != nil {
				return inerr
			}
			if info.IsDir() {
				if dir != path && c.skipDir(info.Name()) {
					return filepath.SkipDir
				}

				var dirh *os.File
				dirh, err = os.Open(path)
				if err != nil {
					return
				}
				defer dirh.Close()

				var filenames []string
				filenames, err = dirh.Readdirnames(0)
				if err != nil {
					return
				}

				if profile.Dir != nil && profile.Dir.DirMatches(path, filenames) {
					relpath, abspath := c.relAbsPath(path)
					found = append(found, profile.Unit(abspath, relpath, c, info))
					if profile.TopLevelOnly {
						return filepath.SkipDir
					}
					// skip trying to match the files if gems or apps are found
					if profile.Name == "Ruby Gem" || profile.Name == "Ruby app" {
						skipFiles = true
					}
				}
			} else {
				if !skipFiles && profile.File != nil && profile.File.FileMatches(path) {
					relpath, abspath := c.relAbsPath(path)
					found = append(found, profile.Unit(abspath, relpath, c, info))
				}
			}
			return
		})
	}

	return
}
开发者ID:pombredanne,项目名称:srcscan,代码行数:59,代码来源:srcscan.go

示例8: getImagePaths

func getImagePaths(pth string) (chan string, error) {
	const pathBufSize = 10

	pathsChan := make(chan string, pathBufSize)

	var pathInfo os.FileInfo

	if pi, err := os.Stat(pth); err == nil {
		pathInfo = pi
	} else {
		return nil, err
	}

	if pathInfo.IsDir() {
		go func() {
			var dir *os.File

			if d, err := os.Open(pth); err == nil {
				dir = d
			} else {
				fmt.Errorf(err.Error())
				pathsChan <- ""
				return
			}

			for {
				var entryNames []string
				if entNames, err := dir.Readdirnames(pathBufSize); err == nil {
					entryNames = entNames
				} else {
					fmt.Errorf(err.Error())
					pathsChan <- ""
					return
				}

				for _, entName := range entryNames {
					p := pth + "/" + entName

					if pStat, err := os.Stat(p); err == nil {
						if !pStat.IsDir() && isSupportedImageFormat(p) {
							pathsChan <- p
						}
					} else {
						fmt.Errorf(err.Error())
					}
				}
			}
		}()
	} else if !pathInfo.IsDir() && isSupportedImageFormat(pth) {
		pathsChan <- pth
	} else {
		return nil, errors.New("The specified file is not an image file.")
	}

	return pathsChan, nil
}
开发者ID:dbratus,项目名称:impack,代码行数:56,代码来源:image_paths.go

示例9: checkForRepo

// Check current directory for existing repo.
func checkForRepo(file *os.File) bool {
	names, err := file.Readdirnames(0)
	if err != nil {
		panic(err)
	}
	for _, name := range names {
		if name == ObjectDir {
			return true
		}
	}
	return false
}
开发者ID:skirkpatrick,项目名称:svc,代码行数:13,代码来源:dirutils.go

示例10: sortedStored

func sortedStored(f *os.File) ([]string, error) {
	names, err := f.Readdirnames(-1)
	if err != nil {
		return nil, err
	}
	onlyFull := []string{}
	for _, v := range names {
		if !strings.HasSuffix(v, ".part") {
			onlyFull = append(onlyFull, v)
		}
	}
	sort.Strings(onlyFull)
	return onlyFull, nil
}
开发者ID:zx9597446,项目名称:nodashtube,代码行数:14,代码来源:main.go

示例11: getFileNames

func getFileNames(dirPath string) ([]string, error) {
	var (
		dir *os.File
		err error
	)
	if dir, err = os.Open(dirPath); err != nil {
		return nil, err
	}
	defer dir.Close()

	fns, _ := dir.Readdirnames(-1)
	sort.Strings(fns)
	return fns, nil
}
开发者ID:JWZH,项目名称:go-bitcask,代码行数:14,代码来源:bitcask.go

示例12: processBatchFolder

func processBatchFolder(f *os.File, outdir string) (count int, e error) {
	names, e := f.Readdirnames(-1)
	if e != nil {
		logger.Println("error reading source folder.")
		return 0, e
	}

	for _, name := range names {
		name = filepath.Join(f.Name(), name)
		go runTask(name, outdir)
		count++
	}

	return count, nil
}
开发者ID:haifengwang,项目名称:makeepub,代码行数:15,代码来源:batch.go

示例13: readdir_stat

func readdir_stat(dir string, f *os.File) ([]os.FileInfo, error) {
	names, err := f.Readdirnames(-1)
	if err != nil {
		return nil, err
	}

	fis := make([]os.FileInfo, len(names))
	for i, name := range names {
		fis[i], err = os.Stat(filepath.Join(dir, name))
		if err != nil {
			return nil, err
		}
	}
	return fis, nil
}
开发者ID:hagna,项目名称:prolix,代码行数:15,代码来源:utils.go

示例14: readdir_stat

func readdir_stat(dir string, f *os.File) ([]os.FileInfo, error) {
	names, err := f.Readdirnames(-1)
	if err != nil {
		return nil, err
	}

	fis := make([]os.FileInfo, 0, len(names))
	for _, name := range names {
		fi, err := os.Stat(filepath.Join(dir, name))
		if err != nil {
			continue
		}
		fis = append(fis, fi)
	}
	return fis, nil
}
开发者ID:magenbluten,项目名称:godit,代码行数:16,代码来源:utils.go

示例15: DirFileToTree

func DirFileToTree(f *os.File, path string) (DirTree, error) {
	fi, err := f.Stat()
	if err != nil {
		return nil, fmt.Errorf("reading stats for %s: %s", path, err)
	}

	if fi.IsDir() {
		ret := &DirFolder{
			name:    fi.Name(),
			Entries: []DirTree{},
		}

		names, err := f.Readdirnames(0)
		if err != nil {
			return nil, fmt.Errorf("reading files at %s: %s", path, err)
		}

		for _, name := range names {
			entryPath := path + "/" + name
			f, err := os.Open(entryPath)
			if err != nil {
				// Ignore errors here; best effort.
				continue
			}
			defer f.Close()
			entry, err := DirFileToTree(f, entryPath)
			if err != nil {
				return nil, err
			}
			ret.Entries = append(ret.Entries, entry)
		}

		sort.Sort(byName(ret.Entries))

		return ret, nil
	} else {
		var df *DirFile
		df = &DirFile{
			name: fi.Name(),
			contents: func() (string, error) {
				bs, err := ioutil.ReadFile(path)
				return string(bs), err
			},
		}
		return df, nil
	}
}
开发者ID:filiptc,项目名称:navpatch,代码行数:47,代码来源:dir_tree.go


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