List of utility methods to do Path Relative
String | getRelativeFileName(String filePath, String directoryPath) get Relative File Name String relativeFileName = filePath; if (directoryPath != null) { relativeFileName = filePath.substring(directoryPath.length()); if (relativeFileName.startsWith(File.separator)) relativeFileName = relativeFileName.substring(1); return relativeFileName; |
File | getRelativeFilePath(File absolutePath, File reference) get Relative File Path File relativePath = absolutePath; if (absolutePath.getAbsolutePath().contains(reference.getAbsolutePath())) { relativePath = new File( absolutePath.getAbsolutePath().substring(reference.getAbsolutePath().length() + 1)); return relativePath; |
String | getRelativeFilePath(String filePath, String relativePathPrefix) Get relative path that follows relativePathPrefix . int prefixIndex = filePath.indexOf(relativePathPrefix); if (prefixIndex == -1) return filePath; int relativePathStartIndex = prefixIndex + relativePathPrefix.length() + 1; return filePath.substring(relativePathStartIndex); |
File | getRelativeLastModifiedTimeFile() get Relative Last Modified Time File return new File(LAST_MODIFIED_FILE_NAME); |
String | getRelativeLink(File target, File base) Returns the path of one File relative to another. if (base == null) { return getFullPath(target); } else { return getRelativePath(target, base); |
String | getRelativeName(File file, File root) Strips off the part of the path before the start of the root file. int length = root.getAbsolutePath().length(); String absolutePath = file.getAbsolutePath(); String relativePath; if (absolutePath.length() == length) { if (file.getAbsolutePath().equals(root.getAbsolutePath())) { relativePath = ""; } else { throw new RuntimeException( ... |
String | getRelativeName(final File directory, final File file) get Relative Name final String name = directory.toURI().relativize(file.toURI()).getPath(); if (file.isDirectory()) { return name.endsWith("/") ? name : name + "/"; return name; |
String | getRelativeName(final File file) Strips the leading path up to "config". String absName = file.getAbsolutePath(); int inx = absName.indexOf("config"); if (inx != -1) { return absName.substring(inx, absName.length()); return null; |
String | getRelativeParentDirectory(File base, File file) get Relative Parent Directory return getRelativePath(base, new File(getAbsoluteParentDirectory(file))); |
String | getRelativeTemporaryFilename(String directory, String suffix, boolean autodelete) get Relative Temporary Filename int num = Math.abs(rng.nextInt()); File f = new File(directory + File.separator + String.format("%06d.%s", num, suffix)); while (f.exists()) { num = Math.abs(rng.nextInt()); f = new File(directory + File.separator + String.format("%06d.%s", num, suffix)); f.createNewFile(); if (autodelete) ... |