Package organizers

Class DirectoryHandler

java.lang.Object
organizers.DirectoryHandler

public class DirectoryHandler extends Object
A utility class for searching and retrieving files within a directory.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addFilesInDirectory(File directory, List<String> filePaths)
    Recursively adds the file paths of all files within the specified directory and its subdirectories to the filePaths list.
    static void
    cleanDirectory(String pathToNeededCleanedDirectory)
    Cleans the specified directory by deleting its files and subdirectories recursively.
    getFilesInDirectory(String directoryName)
    Retrieves the file paths of all files within the specified directory and its subdirectories.
    static boolean
    hasFiles(Path directory)
    Checks if the specified directory contains any files.
    static void
    moveMapFileToErrorDirectory(String mapFilePath, int exitCode)
    Moves a map file from the overall actual directory (or other place) to an error directory based on its exit code.
    void
    searchFiles(File directory, String directoryName, List<String> filePaths)
    Recursively searches for the specified directory within the given directory and its subdirectories.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DirectoryHandler

      public DirectoryHandler()
  • Method Details

    • getFilesInDirectory

      public List<String> getFilesInDirectory(String directoryName)
      Retrieves the file paths of all files within the specified directory and its subdirectories.
      Parameters:
      directoryName - the name of the directory to search for
      Returns:
      a list of file paths as strings
    • addFilesInDirectory

      public void addFilesInDirectory(File directory, List<String> filePaths)
      Recursively adds the file paths of all files within the specified directory and its subdirectories to the filePaths list.
      Parameters:
      directory - the current directory being processed
      filePaths - the list to store the file paths found
    • searchFiles

      public void searchFiles(File directory, String directoryName, List<String> filePaths)
      Recursively searches for the specified directory within the given directory and its subdirectories. When the directory is found, adds the file paths of all files within that directory to the filePaths list.
      Parameters:
      directory - the current directory being searched
      directoryName - the name of the directory to search for
      filePaths - the list to store the file paths found
    • hasFiles

      public static boolean hasFiles(Path directory) throws IOException
      Checks if the specified directory contains any files.
      Parameters:
      directory - The directory path.
      Returns:
      true if the directory contains files, false otherwise.
      Throws:
      IOException - If an I/O error occurs while accessing the directory.
    • moveMapFileToErrorDirectory

      public static void moveMapFileToErrorDirectory(String mapFilePath, int exitCode)
      Moves a map file from the overall actual directory (or other place) to an error directory based on its exit code. See also method getMapFilePath in FileHandler class.
      Parameters:
      mapFilePath - The path of the map file to move.
      exitCode - The exit code associated with the map file.
    • cleanDirectory

      public static void cleanDirectory(String pathToNeededCleanedDirectory)
      Cleans the specified directory by deleting its files and subdirectories recursively.
      Parameters:
      pathToNeededCleanedDirectory - The path to the directory that needs to be cleaned.