本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
}