// Parse a directory to build a list of directories to be made at b0x.go
429372
func (d *Dir) Parse(newDir string) []string {
	list := strings.Split(newDir, "/")

	var dirWalk []string

	for indx := range list {
		dirList := ""
		for i := -1; i < indx; i++ {
			dirList += list[i+1] + "/"
		}

		if !d.Exists(dirList) {
			if strings.HasSuffix(dirList, "//") {
				dirList = dirList[:len(dirList)-1]
			}

			dirWalk = append(dirWalk, dirList)
			d.Blacklist = append(d.Blacklist, dirList)
		}
	}

	return dirWalk
}
537766
func listDirsN(dirs []string, N int, root, prefix string) ([]string, error) {
	if N <= 0 {
		return dirs, nil
	}

	allDirs := []string{}
	for _, dir := range dirs {
		files, err := ioutil.ReadDir(path.Join(root, prefix, dir))
		if err != nil {
			return nil, err
		}

		childDirs := []string{}
		for _, f := range files {
			if !f.IsDir() {
				continue
			}

			childDirs = append(childDirs, f.Name())
		}

		nested, err := listDirsN(childDirs, N-1, root, path.Join(prefix, dir))
		if err != nil {
			return nil, err
		}

		for _, n := range nested {
			allDirs = append(allDirs, path.Join(dir, n))
		}
	}

	return allDirs, nil
}
798863
func ReadDir(r Driver, dirname string) ([]os.FileInfo, error) {
	f, err := r.Open(dirname)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	dirs, err := f.Readdir(-1)
	if err != nil {
		return nil, err
	}

	sort.Sort(fileInfos(dirs))
	return dirs, nil
}
1146439
func SplitPathDirEntry(path string) (dir, base string) {
	cleanedPath := filepath.Clean(filepath.FromSlash(path))

	if specifiesCurrentDir(path) {
		cleanedPath += string(os.PathSeparator) + "."
	}

	return filepath.Dir(cleanedPath), filepath.Base(cleanedPath)
}
778907
func (p *Parser) Parse(str string) (*Results, error) {
	var rs Results
	if str == "" {
		return &rs, ErrInvalid
	}

	var (
		errStack []error
		isdir    bool
		first    string
		command  string
	)

	items := strings.Split(str, p.Separator)
	for index, item := range items {
		args, err := shellwords.Parse(item)
		if err != nil {
			errStack = append(errStack, err)
		}
		if len(args) == 0 {
			return &rs, ErrInvalid
		}
		first = args[0]
		isdir = isDir(first)
		if !isdir {
			// Discard err in order not to make an error
			// even if it is not found in your PATH
			command, _ = exec.LookPath(first)
		}
		// Error if it can not be found in your all PATHs
		// or in the current directory
		if command == "" && !isExist(first) {
			err = fmt.Errorf("%s: no such file or directory", first)
			errStack = append(errStack, err)
		}
		rs = append(rs, Result{
			Index:   index + 1,
			Item:    item,
			Args:    args,
			Command: command,
			Errors:  errStack,
		})
	}

	return &rs, nil
}
781120
func listDirectories() [9]string {
	var names = [9]string{internal.CoreMetaDataServiceKey, internal.CoreCommandServiceKey, internal.CoreDataServiceKey,
		internal.ExportDistroServiceKey, internal.ExportClientServiceKey, internal.SupportLoggingServiceKey,
		internal.SupportSchedulerServiceKey, internal.SupportNotificationsServiceKey, internal.SystemManagementAgentServiceKey}

	for i, name := range names {
		names[i] = strings.Replace(name, internal.ServiceKeyPrefix, "", 1)
	}

	return names
}
66283
func (f *Fibre) Dir(p, dir string) {
	f.Get(p+"*", func(c *Context) error {
		return c.File(dir + c.Param("*"))
	})
}
797167
func parseDirents(dirPath string, buf []byte) (entries []string, err error) {
	bufidx := 0
	for bufidx < len(buf) {
		dirent := (*syscall.Dirent)(unsafe.Pointer(&buf[bufidx]))
		// On non-Linux operating systems for rec length of zero means
		// we have reached EOF break out.
		if runtime.GOOS != "linux" && dirent.Reclen == 0 {
			break
		}
		bufidx += int(dirent.Reclen)
		// Skip if they are absent in directory.
		if isEmptyDirent(dirent) {
			continue
		}
		bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0]))
		var name = string(bytes[0:clen(bytes[:])])
		// Reserved names skip them.
		if name == "." || name == ".." {
			continue
		}

		switch dirent.Type {
		case syscall.DT_DIR:
			entries = append(entries, name+slashSeparator)
		case syscall.DT_REG:
			entries = append(entries, name)
		case syscall.DT_LNK, syscall.DT_UNKNOWN:
			// If its symbolic link, follow the link using os.Stat()

			// On Linux XFS does not implement d_type for on disk
			// format << v5. Fall back to OsStat().
			var fi os.FileInfo
			fi, err = os.Stat(pathJoin(dirPath, name))
			if err != nil {
				// If file does not exist, we continue and skip it.
				// Could happen if it was deleted in the middle while
				// this list was being performed.
				if os.IsNotExist(err) {
					continue
				}
				return nil, err
			}
			if fi.IsDir() {
				entries = append(entries, name+slashSeparator)
			} else if fi.Mode().IsRegular() {
				entries = append(entries, name)
			}
		default:
			// Skip entries which are not file or directory.
			continue
		}
	}
	return entries, nil
}
518098
func (f *File) Readdir() ([]*File, error) {
	if !f.IsDir() {
		return nil, errors.New("not a directory")
	}
	return f.img.readdir(f.subdirOffset)
}
855431
func (f *File) ReadDir() ([]Dir, error) {
	var dirs []Dir
	err := f.walkDir(func(name []byte, ino uint32) bool {
		dirs = append(dirs, Dir{string(name), ino})
		return true
	})
	return dirs, err
}
84525
func (d *Driver) dir(id string) string {
	return filepath.Join(d.info.HomeDir, filepath.Base(id))
}
510578
func ParseGoMod(dir string) (result []Module, err error) {
	cmd := exec.Command("go", "list", "-m", "-json", "all")
	cmd.Dir = dir
	goModData, err := cmd.Output()
	if err != nil {
		return
	}

	modsData := reJSONObj.FindAll(goModData, -1)

	result = make([]Module, len(modsData))
	for i, d := range modsData {
		mod := Module{}
		if err = json.Unmarshal(d, &mod); err != nil {
			return []Module{}, err
		}
		result[i] = mod
	}

	return
}
663489
func (d *Driver) dir(id string) string {
	return filepath.Join(d.dataRoot, filepath.Base(id))
}
545207
func readDirNames(dirname string) ([]string, error) {
	f, err := os.Open(dirname)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	names, err := f.Readdirnames(-1)
	if err != nil {
		return nil, err
	}
	sort.Strings(names)
	return names, nil
}
1023374
func (f *FilesystemIO) ReadDir(dirname string) ([]os.FileInfo, error) {
	return ioutil.ReadDir(dirname)
}
1180259
func (mo *Mo) ParseFile(f string) {
	// Check if file exists
	info, err := os.Stat(f)
	if err != nil {
		return
	}

	// Check that isn't a directory
	if info.IsDir() {
		return
	}

	// Parse file content
	data, err := ioutil.ReadFile(f)
	if err != nil {
		return
	}

	mo.Parse(data)
}
1009815
func listDirectories(path string) ([]string, error) {
	names := []string{}
	items, err := ioutil.ReadDir(path)
	if err != nil {
		return names, err
	}

	for _, item := range items {
		// We only want directories
		if item.IsDir() {
			currentDir := filepath.Join(path, item.Name())
			names = append(names, currentDir)

			// Do some recursion
			subNames, err := listDirectories(currentDir)
			if err == nil {
				names = append(names, subNames...)
			}
		}
	}

	return names, nil
}