public class PathUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Path |
absoluteToJIPipeUserDirRelative(Path path) |
static void |
copyDirectory(Path sourcePath,
Path targetPath,
JIPipeProgressInfo progressInfo) |
static void |
copyDirectory(Path sourcePath,
Path targetPath,
Predicate<Path> directoryFilter,
JIPipeProgressInfo progressInfo) |
static void |
copyOrLink(Path source,
Path target,
JIPipeProgressInfo progressInfo) |
static Path |
createDirectories(Path path)
Same as Files.createDirectories, but throws a
RuntimeException |
static Path |
createGlobalTempDirectory(String prefix)
Create a unique subdirectory rooted at system-wide temporary directory
|
static Path |
createGlobalTempFilePath(String prefix,
String suffix)
Creates a path to a file that does not exist yet
The file will be located in the system-wide temporary path
|
static Path |
createSubTempFilePath(Path root,
String prefix,
String suffix)
Creates a path to a file that does not exist yet
|
static Path |
createTempSubDirectory(Path root)
Create a unique subdirectory rooted at the root path
|
static Path |
createTempSubDirectory(Path root,
String prefix)
Create a unique subdirectory rooted at the root path
|
static void |
deleteDirectoryRecursively(Path path,
JIPipeProgressInfo progressInfo) |
static void |
deleteIfExists(Path path,
JIPipeProgressInfo progressInfo) |
static List<String> |
disassemble(Path path) |
static boolean |
ensureEmptyFolder(Component parent,
Path path)
Ensures that the path exists and is empty
|
static Path |
ensureExtension(Path path,
String extension,
String... alternativeExtensions)
Ensures that the file name of the path has one of the provided extensions
|
static void |
ensureParentDirectoriesExist(Path path)
Ensures that the parent directories of the path exist.
|
static Path |
findAnyOf(Path... paths)
Returns the first path that exists
|
static Path |
findFileByExtensionIn(Path folder,
String... extensions)
Finds a file in the specified folder with given extension
|
static Path |
findFileByExtensionRecursivelyIn(Path folder,
String... extensions)
Finds a file in the specified folder with given extension
|
static List<Path> |
findFilesByExtensionIn(Path folder,
String... extensions)
Finds a file in the specified folder with given extension
|
static Path |
getImageJDir()
Gets the ImageJ directory
|
static Path |
getJIPipeUserDir()
Returns the JIPipe user directory
|
static Path |
getJIPipeUserDirBase()
Returns the base directory that contains all profiles
|
static Path |
getLegacyJIPipeUserDir()
Gets the legacy user directory.
|
static String |
getName(Path path,
int i) |
static String |
getPathNameSafe(Path path) |
static boolean |
isExecutable(Path path)
Checks if a file exists and is an executable
|
static List<Path> |
listDirectory(Path directory) |
static List<Path> |
listSubDirectories(Path folder)
Finds a file in the specified folder with given extension
|
static void |
makeAllUnixExecutable(Path dir,
JIPipeProgressInfo progressInfo)
Marks all files in that directory as Unix executable
|
static void |
makeUnixExecutable(Path path)
Makes a file/directory executable
Does nothing if the OS is Windows
|
static Path |
normalize(Path path) |
static void |
normalizeList(List<Path> paths)
Converts UNIX paths to Windows and Windows paths to UNIX
|
static Path |
orElse(Path firstChoice,
Path alternative)
Returns the first path if it exists or the alternative path if it doesn't
|
static Path |
relativeJIPipeUserDirToAbsolute(Path path)
Converts relative paths to absolute paths, relative to the ImageJ directory
Absolute paths are left unchanged
|
static Path |
resolveAndMakeSubDirectory(Path directory,
Path name) |
static Path |
resolveAndMakeSubDirectory(Path directory,
String name) |
public static void makeUnixExecutable(Path path)
path
- the pathpublic static Path resolveAndMakeSubDirectory(Path directory, String name)
public static void copyDirectory(Path sourcePath, Path targetPath, JIPipeProgressInfo progressInfo)
public static void copyDirectory(Path sourcePath, Path targetPath, Predicate<Path> directoryFilter, JIPipeProgressInfo progressInfo)
public static void deleteDirectoryRecursively(Path path, JIPipeProgressInfo progressInfo)
public static List<Path> listDirectory(Path directory) throws IOException
IOException
public static void copyOrLink(Path source, Path target, JIPipeProgressInfo progressInfo)
public static Path findFileByExtensionIn(Path folder, String... extensions)
folder
- the pathextensions
- Should contain the dotpublic static Path findFileByExtensionRecursivelyIn(Path folder, String... extensions)
folder
- the pathextensions
- Should contain the dotpublic static List<Path> findFilesByExtensionIn(Path folder, String... extensions)
folder
- the pathextensions
- Should contain the dotpublic static List<Path> listSubDirectories(Path folder)
folder
- the pathpublic static void normalizeList(List<Path> paths)
paths
- the paths. This list must be modifiablepublic static Path findAnyOf(Path... paths)
paths
- pathspublic static Path getLegacyJIPipeUserDir()
public static Path getJIPipeUserDirBase()
public static Path getJIPipeUserDir()
public static Path getImageJDir()
public static Path relativeJIPipeUserDirToAbsolute(Path path)
path
- the pathpublic static boolean ensureEmptyFolder(Component parent, Path path)
parent
- the parent component for the dialog boxpath
- the pathpublic static Path ensureExtension(Path path, String extension, String... alternativeExtensions)
path
- the pathextension
- the extension (should include the dot)alternativeExtensions
- alternative extensions that are also valid (should include the dot)public static void ensureParentDirectoriesExist(Path path)
path
- the pathpublic static Path orElse(Path firstChoice, Path alternative)
firstChoice
- the first choice. can be null.alternative
- the alternativepublic static void makeAllUnixExecutable(Path dir, JIPipeProgressInfo progressInfo)
dir
- the directoryprogressInfo
- the progresspublic static Path createGlobalTempDirectory(String prefix)
prefix
- the prefix (can be null, but not recommended)public static Path createTempSubDirectory(Path root)
root
- the root directorypublic static Path createTempSubDirectory(Path root, String prefix)
root
- the root directoryprefix
- the prefix (can be null)public static Path createGlobalTempFilePath(String prefix, String suffix)
prefix
- the file name prefix (can be null)suffix
- the file name suffix (can be null)public static Path createSubTempFilePath(Path root, String prefix, String suffix)
root
- the root directoryprefix
- the file name prefix (can be null)suffix
- the file name suffix (can be null)public static Path createDirectories(Path path)
RuntimeException
path
- the pathpublic static boolean isExecutable(Path path)
path
- the filepublic static void deleteIfExists(Path path, JIPipeProgressInfo progressInfo)
Copyright © 2020–2025 Leibniz Institute for Natural Product Research and Infection Biology - Hans Knöll Institute (HKI). All rights reserved.