Package io.sf.jclf.io

Class Dir

java.lang.Object
io.sf.jclf.io.Dir

public class Dir extends Object
Wildcard-enabled directory utility.

Mainly useful as a WildcardFilter showcase.

Example of usage:

java -cp jclf.jar io.sf.jclf.io.Dir "/etc/h*"
  • Constructor Details

    • Dir

      public Dir()
  • Method Details

    • main

      public static void main(String[] args)
    • baseName

      public static String baseName(String path)
      Gets the basename of the path.

      If the path corresponds to a file, returns the path to parent directory, or null if there isn't, otherwise returns itself (as absolute path)

      Parameters:
      path - the path
      Returns:
      the basename, or null if there isn't
    • wildcardFilter

      public static int wildcardFilter(String wildcardPath, Dir.FilterListener listener)
      Given a path with wildcards (like /foo*\/*\/bar), calls a listener for each matching path found in the local file structure.
      Parameters:
      wildcardPath - the path with wildcards.
      listener - the listener.
      Returns:
      the number of matching files found.
    • copyFile

      public static boolean copyFile(File in, File dest, boolean force)
      Copies a file.
      Parameters:
      in - the file to be copied.
      dest - the destination path.
      force - if true and the destination file exists, it will be removed.
      Returns:
      true if the action was completed, false otherwise.
    • deepCopy

      public static boolean deepCopy(File in, File destDir)
      Copies an origin file or directory to a destination path.

      If the origin id a directory, all files and directories inside it are copied as well.

      Parameters:
      in - the origin file.
      destDir - destination path.
      Returns:
      true if the action was completed, false otherwise.
    • deleteRecursive

      public static boolean deleteRecursive(File path)
      Recursively deletes a directory and all files and directories inside.
      Parameters:
      path - the path to the directory.
      Returns:
      true if the action was completed, false otherwise.