Get the listing of all files under the given directories.

@param fs
the filesystem
@param paths
the paths whose directory listing is to be retrieved
@return the directory expansion for all paths provided
@throws IOException
498090
private static List<CopyPath> expandDirectories(FileSystem fs,
      List<Path> paths, Path dstPath)
      throws IOException {
    List<CopyPath> newList = new ArrayList<CopyPath>();
    FileSystem dstFs = dstPath.getFileSystem(defaultConf);

    boolean isDstFile = false;
    try {
      FileStatus dstPathStatus = dstFs.getFileStatus(dstPath);
      if (!dstPathStatus.isDir()) {
        isDstFile = true;
      }
    } catch (FileNotFoundException e) {
      isDstFile = true;
    }

    for (Path path : paths) {
      FileStatus pathStatus = fs.getFileStatus(path);
      if (!pathStatus.isDir()) {
        // This is the case where the destination is a file, in this case, we
        // allow only a single source file. This check has been done below in
        // FastCopy#parseFiles(List, String[])
        if (isDstFile) {
          newList.add(new CopyPath(path, dstPath));
        } else {
          newList.add(new CopyPath(path, new Path(dstPath, path.getName())));
        }
      } else {
        // If we are copying /a/b/c into /x/y/z and 'z' does not exist, we
        // create the structure /x/y/z/f*, where f* represents all files and
        // directories in c/
        Path rootPath = dstPath;
        // This ensures if we copy a directory like /a/b/c to a directory
        // /x/y/z/, we will create the directory structure /x/y/z/c, if 'z'
        // exists.
        if (dstFs.exists(dstPath)) {
          rootPath = new Path(dstPath, pathStatus.getPath().getName());
        }
        getDirectoryListing(pathStatus, fs, newList, rootPath);
      }
    }
    return newList;
  }
1166632
public static ArrayList<File> getFilesInDirectoryTree(String path) {
		File directory = new File(path);
		return getContentsInDirectoryTree(directory, "*", true, false);
	}
167085
public static List<File> findFiles(final String start, final String[] extensions)
	{
		final List<File> files = new ArrayList<>();
		final Stack<File> dirs = new Stack<>();
		final File startdir = new File(start);
		if (startdir.isDirectory())
		{
			dirs.push(new File(start));
		}
		while (dirs.size() > 0)
		{
			final File dirFiles = dirs.pop();
			final String s[] = dirFiles.list();
			if (s != null)
			{
				for (final String element : s)
				{
					final File file = new File(
						dirFiles.getAbsolutePath() + File.separator + element);
					if (file.isDirectory())
					{
						dirs.push(file);
					}
					else if (match(element, extensions))
					{
						files.add(file);
					}
				}
			}
		}
		return files;
	}
311931
public List<FileInfo> getFileInfos(List<URI> paths) throws IOException {
    checkArgument(paths != null, "paths must not be null");
    logger.atFine().log("getFileInfos(%d paths)", paths.size());

    if (paths.size() == 1) {
      return new ArrayList<>(Collections.singleton(getFileInfo(paths.get(0))));
    }

    int maxThreads = gcs.getOptions().getBatchThreads();
    ExecutorService fileInfoExecutor =
        maxThreads == 0
            ? MoreExecutors.newDirectExecutorService()
            : Executors.newFixedThreadPool(
                Math.min(maxThreads, paths.size()), DAEMON_THREAD_FACTORY);
    try {
      List<Future<FileInfo>> infoFutures = new ArrayList<>(paths.size());
      for (URI path : paths) {
        infoFutures.add(fileInfoExecutor.submit(() -> getFileInfo(path)));
      }
      fileInfoExecutor.shutdown();

      List<FileInfo> infos = new ArrayList<>(paths.size());
      for (Future<FileInfo> infoFuture : infoFutures) {
        try {
          infos.add(infoFuture.get());
        } catch (InterruptedException | ExecutionException e) {
          if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
          }
          throw new IOException(
              String.format("Failed to getFileInfos for %d paths", paths.size()), e);
        }
      }
      return infos;
    } finally {
      fileInfoExecutor.shutdownNow();
    }
  }
1289339
def join_paths(fnames:FilePathList, path:PathOrStr='.')->Collection[Path]:
    ""
    path = Path(path)
    return [join_path(o,path) for o in fnames]
591946
public static List<File> getFilesByExtension(File dir, String[] extensions)
    {
        if (!dir.isDirectory() || extensions == null)
            return Collections.emptyList();
        List<File> files = new ArrayList<File>();
        addFilesByExtension(files, dir, extensions);
        return files;
    }
116384
private function setDirectories($paths)
    {
        if (!empty($paths)) {
            foreach ($paths as $key => $dir) {
                $path = str_replace('.', DS, $dir);

                //Iterate through all paths and filter with extension provided
                $recursiveExtensionFilter = new FileExtensionFilter(
                    new \RecursiveDirectoryIterator($path)
                );

                // loop through the directory listing
                // we need to create a RecursiveIteratorIterator instance
                foreach ($recursiveExtensionFilter as $item) {
                    $alias = str_replace('.php', '', $item->getPathName());

                    $alias = implode('\\', array_map('ucfirst', explode(DS, $alias)));
                    if (!isset($this->directories[$alias])) {
                        $this->directories[str_replace('Src', '', $alias)] = str_replace('\\', '/', $item->getPathName());
                    }
                }
            }
        }
    }
1087227
private void getDescFiles(File dir, Collection<File> files) {
        if (dir.isDirectory()) {
            for (File file : dir.listFiles()) {
                if (file.isDirectory()) {
                    getDescFiles(file, files);
                } else if (file.getName().equals(DESC)) {
                    files.add(file);
                }
            }
        }
    }
220566
public List<Path> getExtraFilesDirectories() {
    return extraFilesDirectories == null
        ? null
        : extraFilesDirectories.stream().map(File::toPath).collect(Collectors.toList());
  }
615437
function getFoldersAndFiles(fpath, folders, files){
	fs.readdirSync(fpath).forEach(function(name){
		var stat = fs.statSync(fpath + name);
		if(stat.isDirectory()){
			folders.push({
				path : fpath,
				name : name
			});
			
			getFoldersAndFiles(fpath + name + '/', folders, files);
		}else{
			files.push({
				path : fpath,
				name : name
			});
		}
	});
}
401807
private static Collection<Path> findFiles(FileSystem fs, final String contains) throws IOException {
        final ArrayList<Path> rv = new ArrayList<>();
        Iterator<Path> dirs = fs.getRootDirectories().iterator();
        Files.walkFileTree(dirs.next(), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
                if (file.toString().contains(contains)) {
                    rv.add(file);
                }
                return FileVisitResult.CONTINUE;
            }
        });
        if (dirs.hasNext()) {
            // There is more than one root directory.
            throw new IOException("FileSystem had more than one root directory: " + fs);
        }
        return rv;
    }
1072870
public static ArrayList<Path> listFilesByModificationTime(FileSystem fs, Path directory, long olderThan)
          throws IOException {
    ArrayList<LocatedFileStatus> fstats = new ArrayList<>();

    RemoteIterator<LocatedFileStatus> itr = fs.listFiles(directory, false);
    while( itr.hasNext() ) {
      LocatedFileStatus fileStatus = itr.next();
      if(olderThan>0) {
        if( fileStatus.getModificationTime()<=olderThan )
          fstats.add(fileStatus);
      }
      else {
        fstats.add(fileStatus);
      }
    }
    Collections.sort(fstats, new ModifTimeComparator() );

    ArrayList<Path> result = new ArrayList<>(fstats.size());
    for (LocatedFileStatus fstat : fstats) {
      result.add(fstat.getPath());
    }
    return result;
  }
740752
@Optional
  @InputFiles
  public FileCollection getExtraFilesDirectoriesAsInputFiles() {
    if (extraFilesDirectories == null) {
      return null;
    }
    FileCollection files = project.files();
    for (File directory : extraFilesDirectories) {
      files = files.plus(project.fileTree(directory));
    }
    return files;
  }
188013
def ListDirectory(self, pathspec, depth=0):
    """"""
    # Limit recursion depth
    if depth >= self.request.max_depth:
      return

    try:
      fd = vfs.VFSOpen(pathspec, progress_callback=self.Progress)
      files = fd.ListFiles(ext_attrs=self.request.collect_ext_attrs)
    except (IOError, OSError) as e:
      if depth == 0:
        # We failed to open the directory the server asked for because dir
        # doesn't exist or some other reason. So we set status and return
        # back to the caller ending the Iterator.
        self.SetStatus(rdf_flows.GrrStatus.ReturnedStatus.IOERROR, e)
      else:
        # Can't open the directory we're searching, ignore the directory.
        logging.info("Find failed to ListDirectory for %s. Err: %s", pathspec,
                     e)
      return

    # If we are not supposed to cross devices, and don't know yet
    # which device we are on, we need to find out.
    if not self.request.cross_devs and self.filesystem_id is None:
      dir_stat = fd.Stat()
      self.filesystem_id = dir_stat.st_dev

    for file_stat in files:

      if stat.S_ISDIR(int(file_stat.st_mode)):
        # Do not traverse directories in a different filesystem.
        is_same_fs = self.filesystem_id == file_stat.st_dev
        if is_same_fs or self.request.cross_devs:
          for child_stat in self.ListDirectory(file_stat.pathspec, depth + 1):
            yield child_stat

      yield file_stat
341923
public void expandClasspath(String... paths) {
        if (paths == null || paths.length == 0) {
            return;
        }
        for (String path: paths) {
            expandClasspath(new File(PathUtil.resolve(path)));
        }
    }
1145129
public synchronized FileSystem getFs() throws IOException {
    if (this.fs == null) {
      Path sysDir = getSystemDir();
      this.fs = sysDir.getFileSystem(getConf());
    }
    return fs;
  }
228007
private Path[] listPaths(final Path path)
      throws IOException {
    Path[] children = null;
    ArrayList<Path> tmpChildrenPath = new ArrayList<>();
    if (fs.isDirectory(path)) {
      // Get children's path list.
      FileStatus[] chiledrenFileStatus = pathFilter == null ? fs.listStatus(path) : fs.listStatus(path, pathFilter);
      for (FileStatus childFileStatus : chiledrenFileStatus) {
        tmpChildrenPath.add(childFileStatus.getPath());
      }
      children = tmpChildrenPath.toArray(new Path[tmpChildrenPath.size()]);
    }
    if (children == null) {
      children = EMPTY_PATH_ARRAY;
    }
    if (comparator != null && children.length > 1) {
      Arrays.sort(children, comparator);
    }
    return children;
  }