Given a directory, determine if it  (or any subdirectory) contains a file
whose format we understand.

@param directory directory to process
@return ProjectFile instance if we can process anything, or null
436385
private ProjectFile handleFileInDirectory(File directory) throws Exception
   {
      List<File> directories = new ArrayList<File>();
      File[] files = directory.listFiles();

      if (files != null)
      {
         // Try files first
         for (File file : files)
         {
            if (file.isDirectory())
            {
               directories.add(file);
            }
            else
            {
               UniversalProjectReader reader = new UniversalProjectReader();
               ProjectFile result = reader.read(file);
               if (result != null)
               {
                  return result;
               }
            }
         }

         // Haven't found a file we can read? Try the directories.
         for (File file : directories)
         {
            ProjectFile result = handleDirectory(file);
            if (result != null)
            {
               return result;
            }
         }
      }
      return null;
   }
902518
public static void deleteDirectory(File directory) throws IOException {
    requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL);

    if (!directory.exists()) {
      return;
    }

    Path path = directory.toPath();
    if (Files.isSymbolicLink(path)) {
      throw new IOException(format("Directory '%s' is a symbolic link", directory));
    }
    if (directory.isFile()) {
      throw new IOException(format("Directory '%s' is a file", directory));
    }
    deleteDirectoryImpl(path);

    if (directory.exists()) {
      throw new IOException(format("Unable to delete directory '%s'", directory));
    }
  }
765673
private void push(File directory) {
		// at this point file is guaranteed to be a directory
		stack.push(workingDirectory);
		workingDirectory = new Directory(directory);
		if (relativePath) {
			pathComponents.push(directory.getName());
		}
	}
830680
@Override
	public boolean cd(String directory) {
		if (StrUtil.isBlank(directory)) {
			// 当前目录
			return true;
		}
		try {
			channel.cd(directory.replaceAll("\\\\", "/"));
			return true;
		} catch (SftpException e) {
			return false;
		}
	}
785152
private static String checkFolder(String directory) {
        File dir = new File(directory);
        if (dir.isFile()) {
            directory = dir.getParent();
        }
        createFolder(directory);
        return directory;
    }
280854
public function isFile($directory = null)
    {
        $directory = ($directory) ?: $this->fileDirectory;
        $isFile = is_file($this->publicDirectory . $directory . $this->file);
        return $isFile;
    }
76219
private File searchFile(File directory, String pattern) {
        if (!directory.isDirectory()) {
            throw new IllegalArgumentException("Not a directly: "+directory);
        }
        File[] files = directory.listFiles();
        assert files != null; //checked for directly above.
        for (File file : files) {
            if (file.getName().matches(pattern)) return file;
        }
        return null;
    }
264769
public static void purgeDirectory(File directory) {

        if (directory.canRead() && directory.isDirectory()) {
            File[] files = directory.listFiles();
            for (int i = 0; i < files.length; i++) {
                File f = files[i];
                if (f.isDirectory()) {
                    purgeDirectory(f);
                }
                if (f.canWrite()) {
                    f.delete();
                }
            }
            directory.delete();
        }
    }
844437
public static void cleanDirectory(File directory) throws IOException {
    requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL);

    Path path = directory.toPath();
    if (!path.toFile().exists()) {
      return;
    }

    cleanDirectoryImpl(path);
  }
319960
function processDirectory(directory: string) {
      // If we were rejected then we should not continue.
      if (rejected === true) {
        return;
      }
      // We are now waiting on this asynchronous task.
      waiting++;
      // Read the directory...
      fs.readdir(directory, (error, fileNames) => {
        if (error) {
          return reject(error);
        }
        // Process every file name that we got from reading the directory.
        for (let i = 0; i < fileNames.length; i++) {
          processFilePath(directory, fileNames[i]);
        }
        // We are done with this async task.
        done();
      });
    }
638685
public ScanPaths determineSignatureScannerPaths(final File directory) throws BlackDuckIntegrationException {
        if (directory == null) {
            throw new IllegalArgumentException("null is not a valid directory");
        }

        if (!directory.isDirectory()) {
            throw new IllegalArgumentException(String.format("%s is not a valid directory", directory.getAbsolutePath()));
        }

        if (!directory.exists()) {
            throw new IllegalArgumentException(String.format("%s does not exist.", directory.getAbsolutePath()));
        }

        boolean managedByLibrary = false;
        File installDirectory = directory;
        final File[] blackDuckScanInstallationDirectories = directory.listFiles(file -> ScannerZipInstaller.BLACK_DUCK_SIGNATURE_SCANNER_INSTALL_DIRECTORY.equals(file.getName()));
        if (blackDuckScanInstallationDirectories.length == 1) {
            logger.debug("The directory structure was likely created by the installer");
            installDirectory = findFirstFilteredFile(blackDuckScanInstallationDirectories[0], EXCLUDE_NON_SCAN_CLI_DIRECTORIES_FILTER, "No scan.cli directories could be found in %s.");
            managedByLibrary = true;
        } else {
            logger.debug(String.format("The directory structure was likely created manually - be sure the jre folder exists in: %s", installDirectory.getAbsolutePath()));
        }

        final String pathToJavaExecutable;
        final String bdsJavaHome = intEnvironmentVariables.getValue(BDS_JAVA_HOME);
        if (StringUtils.isNotBlank(bdsJavaHome)) {
            pathToJavaExecutable = findPathToJavaExe(new File(bdsJavaHome));
        } else {
            final File jreContentsDirectory = findFirstFilteredFile(installDirectory, JRE_DIRECTORY_FILTER, "Could not find the 'jre' directory in %s.");
            pathToJavaExecutable = findPathToJavaExe(jreContentsDirectory);
        }

        final File libDirectory = findFirstFilteredFile(installDirectory, LIB_DIRECTORY_FILTER, "Could not find the 'lib' directory in %s.");

        final String pathToOneJar = findPathToStandaloneJar(libDirectory);
        final String pathToScanExecutable = findPathToScanCliJar(libDirectory);

        return new ScanPaths(pathToJavaExecutable, pathToOneJar, pathToScanExecutable, managedByLibrary);
    }
774170
public static boolean deleteContents(File directory) {
    File[] files = directory.listFiles();
    boolean success = true;
    if (files != null) {
      for (File file : files) {
        success &= deleteRecursively(file);
      }
    }
    return success;
  }
357924
public static final Set<File> findFileByDirAndSubBySuffix(File dir,String ...suffix)
	{
		return findFileByDirAndSub(dir,new FileFilter() {
			@Override
			public boolean accept(File pathname) 
				{
					if(pathname.isDirectory())
					{
						return true;
					}
					if(pathname.isFile())
					{
						for(String s:suffix)
						{
							if(pathname.getName().endsWith(s))
							{
								return true;
							}
						}
					}
					return false;
				}
			});
	}
1254020
function readDirectoryFiles(directory) {
  return new Promise((resolve, reject) => {
    fs.readdir(directory, (err, files) => {
      if (err) {
        reject(err);
        return;
      }

      const isFile = fileName => readFileStats(path.join(directory, fileName))
        .then((fstat) => {
          if (fstat.isFile()) {
            return fileName;
          }
          return null;
        });

      Promise.all(files.map(isFile))
        .then(fileList => resolve(fileList.filter(f => f !== null)))
        .catch(reject);
    });
  });
}
1221189
public static void directoryCheck(String dir) throws IOException {
		final File file = new File(dir);

		if (!file.exists()) {
			FileUtils.forceMkdir(file);
		}
	}
702136
public static boolean deleteDirectory(final File dir) {
		boolean success = true;
		if (dir != null && dir.exists()) {
			try {
				if (dir.isDirectory()) {
					for (final File file : dir.listFiles()) {
						if(file == null) {
							return false;
						}
						if (!deleteDirectory(file)) {
							success = false;
							return success;
						}
					}
				}
				if (!dir.delete()) {
					success = false;
					return success;
				}
				return success;
			} catch (Exception e) {
				// Failed to delete files or directory
			}
		}
		return false;
	}
152438
public static void mkdir(File dir) throws IOException{
        if(!dir.exists() && !dir.mkdir())
            throw new IOException("couldn't create directory: "+dir);
    }