/*
Wrapper and error control for scandir(). Returns an array of files in the directory specified.
493718
static function get_directory_list($directory_path)
    {
        $output = false;
        try {
            $output = scandir($directory_path);
            foreach ($output as $key => $file) {
                if (!is_file($directory_path.'/'.$file)) {
                    // just return files please.
                    unset($output[$key]);
                }
            }
        } catch (Exception $e) {
            echo ('Error reading directory: '.var_export($e, true).PHP_EOL);
            die();
        }
        return $output;
    }
1277526
protected function _scanDir($dir)
    {
        $dir = new Folder($dir);
        $contents = $dir->read(true, true);
        if (empty($contents[1])) {
            return [];
        }
        $shells = [];
        foreach ($contents[1] as $file) {
            if (substr($file, -4) !== '.php') {
                continue;
            }
            $shells[] = substr($file, 0, -4);
        }

        return $shells;
    }
164324
public String[] getDirectoryContent(String scannerBaseDir, String[] includes, String[] excludes, boolean followSymlinks, boolean globCaseSensitive) {
        return getDirectoryContent(scannerBaseDir, includes, excludes, followSymlinks, globCaseSensitive, false);
    }
238902
function readDirs(dir, cb)  {
  // find top-level module dirs
  if (Array.isArray(dir)) {
    // dir is a list of paths
    readDirsParallel(dir, cb);
  } else {
    // dir is a single path value
    readDirAbs(dir, cb);
  }
}
333448
function(dir) {
  var methods = [];

  var findConfigFiles = function(dir) {
    fs.readdirSync(dir).forEach(function(file) {
      file = path.join(dir, file);
      var stat = fs.statSync(file);
      if(stat && stat.isDirectory()) {
        findConfigFiles(file);
      } else if(/config.js$/.test(file)) {
        methods.push(file);
      }
    });
  };

  findConfigFiles(dir);

  return methods;
}
1060721
function readdir(modeInfo, dirPath, opts_, cb) {
  opts_ = opts_ || {};
  var isAsync = modeInfo.async;

  // Convert to array if a string
  opts_.include = strToArray(opts_.include);
  opts_.exclude = strToArray(opts_.exclude);

  if (opts_.skipHidden === true) {
    var regex = /^\./;
    if (Array.isArray(opts_.exclude)) {
      opts_.exclude.push(regex);
    } else {
      opts_.exclude = [regex];
    }
  }

  // Set defaults if not provided
  opts_.includeMatchAll = opts_.includeMatchAll ? 'every' : 'some';
  opts_.excludeMatchAll = opts_.excludeMatchAll ? 'every' : 'some';

  if (isAsync === true) {
    fs.readdir(dirPath, function (err, files) {
      if (err) {
        throw err;
      }
      filter(files, cb);
    });
  } else {
    return filterSync(fs.readdirSync(dirPath));
  }

  function strToArray(val) {
    if (val && !Array.isArray(val)) {
      val = [val];
    }
    return val;
  }

  function filterByType(file, cb) {
    // We need the full path so convert it if it isn't already
    var filePath = file;
    if (opts_.detailed === true) {
      filePath = joinPath(file.basePath, file.fileName);
    } else if (!opts_.fullPath) {
      filePath = joinPath(dirPath, file);
    }

    if (isAsync === true) {
      fs.stat(filePath, function (err, stats) {
        var filtered = getFiltered(stats.isDirectory());
        cb(err, filtered);
      });
    } else {
      return getFiltered(fs.statSync(filePath).isDirectory());
    }

    function getFiltered(isDir) {
      // Keep the two names for legacy reasons
      if (opts_.skipDirectories === true || opts_.skipDirs === true) {
        if (isDir) {
          return false;
        }
      }
      if (opts_.skipFiles === true) {
        if (!isDir) {
          return false;
        }
      }
      return file;
    }
  }

  function filterByMatchers(files) {
    var filtered = files.filter(function (fileName) {
      var isExcluded;
      var isIncluded;

      // Don't include if matches exclusion matcher
      if (opts_.exclude) {
        isExcluded = opts_.exclude[opts_.excludeMatchAll](function (matcher) {
          return matches(fileName, matcher);
        });
        if (isExcluded === true) {
          return false;
        }
      }

      // Include if matches inclusion matcher, exclude if it doesn't
      if (opts_.include) {
        isIncluded = opts_.include[opts_.includeMatchAll](function (matcher) {
          return matches(fileName, matcher);
        });
        return isIncluded;
      }

      // Return true if it makes it to here
      return true;
    });

    if (opts_.fullPath === true && opts_.detailed === true) {
      throw new Error('[indian-ocean] Both `fullPath` and `detailed` are `true`. You can only set one or the other.');
    }
    // Prefix with the full path if that's what we asked for
    if (opts_.fullPath === true) {
      return filtered.map(function (fileName) {
        return joinPath(dirPath, fileName);
      });
    }
    // Or return detailed format
    if (opts_.detailed === true) {
      return filtered.map(function (fileName) {
        return { basePath: dirPath, fileName: fileName };
      });
    }

    return filtered;
  }

  function filterSync(files) {
    var filtered = filterByMatchers(files);

    return filtered.map(function (file) {
      return filterByType(file);
    }).filter(identity);
  }

  function filter(files, cb) {
    var filterQ = queue();

    var filtered = filterByMatchers(files);

    filtered.forEach(function (fileName) {
      filterQ.defer(filterByType, fileName);
    });

    filterQ.awaitAll(function (err, namesOfType) {
      cb(err, namesOfType.filter(identity));
    });
  }
}
600114
function readDir (dir, regex = /^(?:)$/) {
  return new Promise((resolve, reject) =>
    fs.readdir(dir, (err, files) => err
      ? reject(err)
      : resolve(Promise.all(files.map(checkFileName.bind(null, dir, regex))))))
    .then(values =>
      [].concat(...values)
        .filter(i => i))
}
188211
public ArrayList<File> scanAllFiles(File directoryToScan) {
		CumulativeFileScannerObserver fileScanner = new CumulativeFileScannerObserver();
		
		DirectoryScanner directoryScanner = new DirectoryScanner(fileScanner);
		for (FileScannerObserver fileScannerObserver : fileScanners) {
			directoryScanner.addFileScanner(fileScannerObserver);
		}
		directoryScanner.setFileFilter(this.fileFilter);
		directoryScanner.scanDirectory(directoryToScan);
		return fileScanner.getResults();
	}
566525
private File[] getFilesInDir(File dir) {
        return dir.listFiles(new FileFilter() {
            public boolean accept(File file) {
                return file.isFile() && !file.getName().equals(ATTEMPTS_JSON_FILE_NAME);
            }
        });
    }
343321
function _emptyDirectoryProm (directory) {

			return new Promise((resolve, reject) => {

				readdir(directory, (err, files) => {
					return err ? reject(err) : resolve(files);
				});

			}).then((files) => {

				const result = [];

					for (let i = 0; i < files.length; ++i) {
						result.push(join(directory, files[i]));
					}

				return Promise.resolve(result);

			}).then((files) => {
				return files.length ? _removeDirectoryContentProm(files) : Promise.resolve();
			});

		}
465246
def _scanDataFiles(self, dataDir, patterns):
        
        numDataFiles = 0
        for pattern in patterns:
            scanPath = os.path.join(dataDir, pattern)
            for filename in glob.glob(scanPath):
                self._addDataFile(filename)
                numDataFiles += 1
        if numDataFiles == 0:
            raise exceptions.EmptyDirException(dataDir, patterns)
1207712
function processDir(options, callback) {
  return fs.readdir(options.path, function(err, filenames) {
    if (err) {
      return callback(err);
    }

    if (options.ignoreDotFiles) {
      filenames = _.filter(filenames, function(filename) {
        return filename[0] !== ".";
      });
    }

    return async.map(filenames, function(filename, done) {
      const abspath = path.join(options.path, filename);

      if (options.statEach === false) {
        return done(null, {
          filename,
          path: abspath,
        });
      }

      stat(abspath, function(statErr, stats) {
        if (statErr) {
          return done(statErr);
        }
        return done(null, stats);
      });
    }, function(mapErr, statsMap) {
      if (mapErr) {
        return callback(err);
      }

      if (!options.ignoreCurDir) {
        const stats = _.cloneDeep(options.dirStats);
        stats.filename = ".";
        statsMap.push(stats);
      }

      if (!options.ignoreUpDir) {
        const abspath = path.join(options.path, "..");
        return stat(abspath, function(statErr, stats) {
          if (err) {
            return callback(err);
          }
          stats.filename = "..";
          statsMap.push(stats);
          return callback(null, statsMap);
        });
      }

      return callback(null, statsMap);
    });
  });
}
727360
public static List<File> getAllFilesFromDir(final File dir)
	{
		final List<File> foundedFileList = new ArrayList<>();
		final File[] children = dir.getAbsoluteFile().listFiles();
		if (children == null || children.length < 1)
		{
			return foundedFileList;
		}
		for (final File child : children)
		{
			// if the entry is not a directory
			if (!child.isDirectory())
			{
				// then
				// entry is a file
				foundedFileList.add(child.getAbsoluteFile());
			}
		}
		return foundedFileList;
	}
1240691
public List<File> scan(Resource resource) {
        Scanner scanner = buildContext.newScanner(new File(resource.getDirectory()), true);
        setupScanner(scanner, resource);
        scanner.scan();
        List<File> files = new ArrayList<File>();
        for (String file : scanner.getIncludedFiles()) {
            files.add(new File(resource.getDirectory(), file));
        }
        return files;
    }
728559
private String[] scanIncludedFiles() {
		final DirectoryScanner scanner = new DirectoryScanner();
		scanner.setBasedir(sourceDirectory);
		scanner.setIncludes(new String[]{inputFilename});
		scanner.scan();
		return scanner.getIncludedFiles();
	}
589067
public static File[] listFilesSortedByModDate(File dir) {
        File[] backupDirFiles = dir.listFiles();
        Arrays.sort(backupDirFiles, new FileComparator());
        return backupDirFiles;
    }
564967
private static Collection<File> findDirsRecursively(File dir) {
		return FileUtils.listFilesAndDirs(dir, FalseFileFilter.FALSE, TrueFileFilter.TRUE);
	}