public final class PathTools
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
PathTools.FileName |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
defaultLocalSearchSubDirs |
private static java.lang.String[] |
documentsDirs |
Modifier | Constructor and Description |
---|---|
private |
PathTools() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addSlash(java.lang.String path) |
static boolean |
anyFilesMatch(java.lang.String dirPath,
java.lang.String filter)
Returns the true if any files in the given directory match the specified filter, which should be a
a glob expression such as "*.{java,class,jar}"
Glob expressions are fairly uniform across platforms.
|
static java.lang.String |
changeExtension(java.lang.String file,
java.lang.String extension) |
static boolean |
exists(java.lang.String fileOrDirectory) |
static java.io.File |
fileFromPath(java.lang.String path) |
static java.io.File |
fileFromPath(java.lang.String path,
boolean mustExist) |
static java.io.File |
findLocalPath(java.lang.Class refType,
java.lang.String name,
java.lang.String... trySubDirs) |
static java.io.File |
findLocalPath(java.lang.String name) |
static java.lang.String |
getAppPath(java.lang.Class referenceClass)
Gets the absolute path to the directory containing the class file for referenceClass.
|
static java.lang.String |
getBaseName(java.lang.String fullName)
Gets the base name of the file -- i.e.
|
static java.lang.String |
getBaseName(java.lang.String fullName,
boolean allowMultiDotExtensions)
Gets the base name of the file -- i.e.
|
static java.lang.String |
getCanonicalPath(java.io.File file)
Unlike the other getCanonicalPath overloads, this one simply uses
File.getCanonicalPath() |
static java.lang.String |
getCanonicalPath(java.lang.String path)
Get the canonical form of a file-system path by:
Converting it to unix format (if Windows)
Replacing
// with /
Replacing /./ with /
Replacing dirname/../ with /
|
static java.lang.String |
getCanonicalPath(java.lang.String path,
boolean addEndSlash,
boolean removeEndSlash,
boolean removeStartSlash,
boolean removeDotSlashAtStart)
Get the canonical form of a file-system path by:
Converting it to unix format (if Windows)
Removing starting slashes (if
removeStartSlash is true)
Adding an ending slash (if addEndSlash is true}
Removing an ending slash (if removeEndSlash is true
Replacing // with /
Replacing /./ with /
Replacing dirname/../ with /
Removing ./ at the start of a path (if removeDotSlashAtStart is true)
|
static java.lang.String |
getDir(java.lang.String fullName)
Get the full parent directory path, including the final slash.
|
static java.lang.String |
getDir(java.lang.String fullName,
boolean includeFinalSlash) |
static java.io.File |
getDocumentsDir() |
static java.lang.String |
getExt(java.lang.String fullName)
Gets the extension of the file including the preceding dot (.)
If the file name contains multiple dot (.) characters, the extension is defined as the segment starting with
the final dot.
|
static java.lang.String |
getExt(java.lang.String fullName,
boolean includeDot,
boolean allowMultiDotExtensions)
Gets the extension of the file including the preceding dot (.)
|
static java.io.File |
getFirstExisting(java.io.File parentDir,
boolean includeDirs,
boolean includeFiles,
java.lang.String... paths) |
static java.io.File |
getHomeDir() |
static boolean |
isDir(java.lang.String directory) |
static boolean |
isFile(java.lang.String file) |
static java.util.List<java.io.File> |
listFiles(java.lang.String dirPath,
java.lang.String filter)
Lists all files in a directory that match the specified filter, which should be a
a glob expression such as "*.{java,class,jar}"
Glob expressions are fairly uniform across platforms.
|
static PathTools.FileName |
parse(java.lang.String fullFilePath) |
static PathTools.FileName |
parse(java.lang.String fullFilePath,
boolean allowMultiDotExtensions) |
static boolean |
verifyWritable(java.io.File file)
Verify that a directory is writeable by writing a new file (and then deleting it).
|
private static java.lang.String[] defaultLocalSearchSubDirs
private static final java.lang.String[] documentsDirs
public static java.lang.String addSlash(java.lang.String path)
public static boolean anyFilesMatch(java.lang.String dirPath, @NotNull java.lang.String filter)
PathMatcher
for glob details.dirPath
- The path of the directory to search.filter
- The glob expression to match files against.public static java.lang.String changeExtension(java.lang.String file, java.lang.String extension)
public static boolean exists(java.lang.String fileOrDirectory)
public static java.io.File fileFromPath(java.lang.String path)
public static java.io.File fileFromPath(java.lang.String path, boolean mustExist)
public static java.io.File findLocalPath(java.lang.Class refType, java.lang.String name, java.lang.String... trySubDirs)
public static java.io.File findLocalPath(java.lang.String name)
@Nullable public static java.lang.String getAppPath(java.lang.Class referenceClass)
null
if security restrictions do not permit resolution of paths.public static java.lang.String getBaseName(java.lang.String fullName)
fullName
- The full file name or path.getBaseName(String, boolean)
public static java.lang.String getBaseName(java.lang.String fullName, boolean allowMultiDotExtensions)
fullName
- The full file name or path.allowMultiDotExtensions
- If true, the extension starts at the first dot (.) encountered, which
means the resulting base name will never contain any dots.
If false, the extension starts at the last dot, so the base name will
contain all dots except the final one.public static java.lang.String getCanonicalPath(java.io.File file)
File.getCanonicalPath()
public static java.lang.String getCanonicalPath(java.lang.String path)
//
with /
/./
with /
dirname/../
with /
path
- The path to canonicalizegetCanonicalPath(String, boolean, boolean, boolean, boolean)
public static java.lang.String getCanonicalPath(java.lang.String path, boolean addEndSlash, boolean removeEndSlash, boolean removeStartSlash, boolean removeDotSlashAtStart)
removeStartSlash
is true)addEndSlash
is true}removeEndSlash
is true//
with /
/./
with /
dirname/../
with /
./
at the start of a path (if removeDotSlashAtStart
is true)path
- The path to canonicalizeaddEndSlash
- If true, any slashes at the end of the path will be removed. i.e. path/
becomes path
removeEndSlash
- If true any path not ending with a slash will have one appended. i.e. path
becomes path/
removeStartSlash
- If true, any slashes at the beginning of the path will be removed. i.e. /path
becomes path
removeDotSlashAtStart
- If this is true and the path starts with ./
, it will be removed. i.e. ./path
becomes path
public static java.lang.String getDir(java.lang.String fullName)
/path/to/fileName.ext | --> | /path/to/ |
/fileName.ext | --> | / |
C:\Windows\System32 | --> | C:\Windows\ |
images\banana.jpg | --> | images\ |
HelloWorld.txt | --> | (empty) |
fullName
- The full path to the file.\
or /
.public static java.lang.String getDir(java.lang.String fullName, boolean includeFinalSlash)
public static java.io.File getDocumentsDir()
public static java.lang.String getExt(java.lang.String fullName)
fullName
- The full file name or path.public static java.lang.String getExt(java.lang.String fullName, boolean includeDot, boolean allowMultiDotExtensions)
fullName
- The full file name or path.includeDot
- allowMultiDotExtensions
- If true, the extension starts at the first dot (.) encountered in
the file name, which means the resulting extension may contain more than one dot.
If false, the extension starts at the last dot, so the extension will
either be empty (if the file has no extension) or it will contain exactly one
dot as its first character. @return The extension of the file including the preceding dot (.)@Nullable public static java.io.File getFirstExisting(@Nullable java.io.File parentDir, boolean includeDirs, boolean includeFiles, java.lang.String... paths)
public static java.io.File getHomeDir()
public static boolean isDir(java.lang.String directory)
public static boolean isFile(java.lang.String file)
public static java.util.List<java.io.File> listFiles(java.lang.String dirPath, @NotNull java.lang.String filter)
PathMatcher
for glob details.dirPath
- The path of the directory to search.filter
- The glob expression to match files against.public static PathTools.FileName parse(java.lang.String fullFilePath)
public static PathTools.FileName parse(java.lang.String fullFilePath, boolean allowMultiDotExtensions)
public static boolean verifyWritable(java.io.File file)
file
- the file or directory to test for writing