sorts ``input_dir`` and tries to reconstruct the subdirectories found
166232
def reconstruct_files(input_dir):
    ''''''
    input_dir = input_dir.rstrip('/')
    with nl.notify('Attempting to organize/reconstruct directory'):
        # Some datasets start with a ".", which confuses many programs
        for r,ds,fs in os.walk(input_dir):
            for f in fs:
                if f[0]=='.':
                    shutil.move(os.path.join(r,f),os.path.join(r,'i'+f))
        nl.dicom.organize_dir(input_dir)
        output_dir = '%s-sorted' % input_dir
        if os.path.exists(output_dir):
            with nl.run_in(output_dir):
                for dset_dir in os.listdir('.'):
                    with nl.notify('creating dataset from %s' % dset_dir):
                        nl.dicom.create_dset(dset_dir)
        else:
            nl.notify('Warning: failed to auto-organize directory %s' % input_dir,level=nl.level.warning)
1328787
function stupidDirsExist(dirs) {
  const check = [];
  dirs.forEach((dir) => {
    check.push(dirExist(dir));
  });

  return Promise.all(check).then((results) => {
    // Combine to single object
    return dirs.reduce(function(prev, item, i) {
      prev[item] = !!results[i];

      return prev;
    }, {});
  });
}
296395
def paths_in_directory(input_directory):
    
    paths = []
    for base_path, directories, filenames in os.walk(input_directory):
        relative_path = os.path.relpath(base_path, input_directory)
        path_components = relative_path.split(os.sep)
        if path_components[0] == ".":
            path_components = path_components[1:]
        if path_components and path_components[0].startswith("."):
            # hidden dir
            continue
        path_components = filter(bool, path_components)  # remove empty components
        for filename in filenames:
            if filename.startswith("."):
                # hidden file
                continue
            paths.append(path_components + [filename])
    return paths
1256542
def get_input_files(dirname, *ext):
    
    filelist = [f for f in os.listdir(dirname) if
                os.path.splitext(f)[-1] in ext]
    return [os.path.join(dirname, f) for f in filelist]
767972
def input_dir(self):
        
        return os.path.abspath(os.path.dirname(self.inputs['job_ini']))
675740
def sort_dict_of_paths(d):
    
    # Find the path that is the deepest, and count the number of parts
    max_rec = max(len(x) if x else 0 for x in d.values())
    # Pad other paths with empty parts to fill in, so that all paths will have the same number of parts (necessary to compare correctly, else deeper paths may get precedence over top ones, since the folder name will be compared to filenames!)
    for key in d.keys():
        if d[key]:
            d[key] = ['']*(max_rec-len(d[key])) + d[key]
    # Sort the dict relatively to the paths alphabetical order
    d_sort = sorted(d.items(), key=lambda x: x[1])
    return d_sort
1290611
def read_dir(input_dir,input_ext,func):
    ''''''
    import os
    for dirpath, dnames, fnames in os.walk(input_dir):
        for fname in fnames:
            if not dirpath.endswith(os.sep):
                dirpath = dirpath + os.sep
            if fname.endswith(input_ext):
                func(read_file(dirpath + fname))
1298255
def fix_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set', 'map'],
                    seqType='both', verbose=False):
    """"""
    # The new modification time.
    timestamp = datetime.datetime.now();
    # Fix the input files for containers in their variadic form.
    if seqType == "both" or seqType == "variadic":
        if verbose:
            print "Fix input files for pre-processing Boost.MPL variadic containers."
        fix_input_files_for_variadic_seq(headerDir, sourceDir, timestamp)
    # Fix the input files for containers in their numbered form.
    if seqType == "both" or seqType == "numbered":
        if verbose:
            print "Fix input files for pre-processing Boost.MPL numbered containers."
        fix_input_files_for_numbered_seq(headerDir, ".hpp", timestamp, containers)
        fix_input_files_for_numbered_seq(sourceDir, ".cpp", timestamp, containers)
1017950
def glob_in_parents(dir, patterns, upper_limit=None):
    """"""

    assert(isinstance(dir, str))
    assert(isinstance(patterns, list))

    result = []

    absolute_dir = os.path.join(os.getcwd(), dir)
    absolute_dir = os.path.normpath(absolute_dir)
    while absolute_dir:
        new_dir = os.path.split(absolute_dir)[0]
        if new_dir == absolute_dir:
            break
        result = glob([new_dir], patterns)
        if result:
            break
        absolute_dir = new_dir

    return result
319905
def ensure_directories_end_in_separator(opts_dict):
    
    assert_has_input_output(opts_dict)
    assert 'is_dir' in opts_dict
    if opts_dict['is_dir']:
        opts_dict['input'] = add_suffix(opts_dict['input'],
                                        get_path_separator())
    opts_dict['output'] = add_suffix(opts_dict['output'], get_path_separator())
1192839
function traverse (root, dirs, collect, next) {
  const rootPath = path.join (root, ...dirs);
  fs.lstat (rootPath, (err0) => {
    if (err0) {
      next (err0);
    } else {
      fs.readdir (rootPath, (_, files) => {
        let pending = files.length;
        for (let file of files) {
          const filePath = path.join (root, ...dirs, file);
          fs.lstat (filePath, (err1, stats) => {
            if (err1) {
              next (err1);
            } else {
              if (stats.isDirectory ()) {
                traverse (root, [...dirs, file], collect, err2 => {
                  if (err2) {
                    next (err2);
                  } else {
                    if (--pending === 0) {
                      next ();
                    }
                  }
                });
              } else {
                if (stats.isFile ()) {
                  collect (dirs, file, files);
                  if (--pending === 0) {
                    next ();
                  }
                }
              }
            }
          });
        }
      });
    }
  });
}
1102795
def sorted(self, wantdirs=False):
        

        def add_dir(dirs, d):
            dirs.add(d)
            logger.debug('add_dir added %s', d)
            if d != self.base:
                parent, _ = os.path.split(d)
                assert parent not in ('', '/')
                add_dir(dirs, parent)

        result = set(self.files)    # make a copy!
        if wantdirs:
            dirs = set()
            for f in result:
                add_dir(dirs, os.path.dirname(f))
            result |= dirs
        return [os.path.join(*path_tuple) for path_tuple in
                sorted(os.path.split(path) for path in result)]
19425
private static List<Path> expandMultiAppInputDirs(List<Path> input)
    {
        List<Path> expanded = new LinkedList<>();
        for (Path path : input)
        {
            if (Files.isRegularFile(path))
            {
                expanded.add(path);
                continue;
            }
            if (!Files.isDirectory(path))
            {
                String pathString = (path == null) ? "" : path.toString(); 
                log.warning("Neither a file or directory found in input: " + pathString);
                continue;
            }

            try
            {
                try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path))
                {
                    for (Path subpath : directoryStream)
                    {

                        if (isJavaArchive(subpath))
                        {
                            expanded.add(subpath);
                        }
                    }
                }
            }
            catch (IOException e)
            {
                throw new WindupException("Failed to read directory contents of: " + path);
            }
        }
        return expanded;
    }
1362173
def getSubdirectories(d):
	'''
	'''
	return [f for f in os.listdir(d) if os.path.isdir(os.path.join(d, f)) ]
108408
def ls_dir(base_dir):
    """"""
    return [
        os.path.join(dirpath.replace(base_dir, '', 1), f)
        for (dirpath, dirnames, files) in os.walk(base_dir)
        for f in files
    ]
785142
def _enter_single_subdir(root_dir):
    """"""
    current_cwd = os.getcwd()
    try:
        dest_dir = root_dir
        dir_list = os.listdir(root_dir)
        if len(dir_list) == 1:
            first = os.path.join(root_dir, dir_list[0])
            if os.path.isdir(first):
                dest_dir = first
        else:
            dest_dir = root_dir
        os.chdir(dest_dir)
        yield dest_dir
    finally:
        os.chdir(current_cwd)
603151
function readDirAbs(dir, cb) {
  fs.readdir(dir, function(err, entries) {
    if (err || !entries) {
      return cb(err, null);
    }
    var items = [];
    entries.forEach(function(entry) {
      items.push(path.join(dir, entry));
    });
    return cb(null, items);
  });
}