Class FilePath

java.lang.Object
de.tsl2.nano.util.FilePath

public class FilePath extends Object
provides actions on a path and all its subdirectories and files.

all use the base function recurse(String, String, String, Function)

Author:
Thomas Schneider
  • Constructor Details

    • FilePath

      public FilePath()
  • Method Details

    • deleteDirectory

      public static int deleteDirectory(String dir)
      deletes all files in a given directory
    • copy

      public static int copy(String dir, String target)
      copies all files in a given directory to the given target
    • move

      public static int move(String dir, String target)
      moves all files in a given directory to the given target
    • foreach

      public static <RESULT> Collection<RESULT> foreach(String dir, String includes, String excludes, String contentRegEx, Function<Path,RESULT> fct)
      Type Parameters:
      RESULT - function result type, to be collected as return value
      Parameters:
      dir - base directory to start on
      includes - optional file name include regular expression
      excludes - optional file name exclude regular expression
      contentRegEx - regular expression to be matched inside the files content
      fct - action to do if file name and content matches
      Returns:
      all results of all function calls
    • recurse

      public static <R> int recurse(String dir, String includes, String excludes, Function<Path,R> action)
      as Paths.get(file).foreach(consumer) walks only the path elements itself from root, this walks through all recursive files/paths starting on given dir.
      Parameters:
      dir - base directory to start on
      includes - optional file name include regular expression
      excludes - optional file name exclude regular expression
      action - if file name matches, this function will be executed. if the function returns a value != null, the result count will be increased.
      Returns:
      count of function calls with result != null
    • read

      public static byte[] read(String file)
    • write

      public static Path write(String file, byte[] bytes)
    • getFileWriter

      public static BufferedWriter getFileWriter(String file)