List of utility methods to do Path Relative Get
String | getRelativePath(File base, File path) get Relative Path return base.toPath().relativize(path.toPath()).toString();
|
String | getRelativePath(File base, File path) get Relative Path try { String relative = base.getCanonicalFile().toURI().relativize(path.getCanonicalFile().toURI()).getPath(); return relative; } catch (IOException e) { return null; |
String | getRelativePath(File base, File target) Returns the relative path from base to target. String baseString = base.getAbsolutePath().replace('\\', '/'); String targetString = target.getAbsolutePath().replace('\\', '/'); String commonPrefix = findGreatestCommonPrefix(baseString, targetString); if (commonPrefix.length() == 0) { throw new IllegalArgumentException("Arguments must have common prefix"); String relativePath = targetString.substring(commonPrefix.length()); if (commonPrefix.length() == baseString.length()) { ... |
String | getRelativePath(File baseDir, File file) get Relative Path if (baseDir.equals(file)) return ""; if (baseDir.getParentFile() == null) return file.getAbsolutePath().substring(baseDir.getAbsolutePath().length()); return file.getAbsolutePath().substring(baseDir.getAbsolutePath().length() + 1); |
String | getRelativePath(File baseDir, File file) get Relative Path String filePath = file.getAbsolutePath(); String basePath = baseDir.getAbsolutePath(); String relativePath = filePath.substring(basePath.length()); if (relativePath.charAt(0) == File.separatorChar) { relativePath = relativePath.substring(1); return relativePath; |
String | getRelativePath(File baseDir, File file) get Relative Path String basePath = baseDir.getAbsolutePath(); if (!basePath.endsWith(File.separator)) { basePath += File.separator; String filePath = file.getAbsolutePath(); if (!filePath.startsWith(basePath)) { throw new IllegalArgumentException("Not dir-relative: " + filePath + " vs " + basePath); String relativePath = filePath.substring(basePath.length()); return relativePath; |
String | getRelativePath(File baseDir, File file) Returns the relative path of file to the file basedir .
final String base = baseDir.getCanonicalPath(); String fileName = file.getCanonicalPath(); if (fileName.startsWith(base)) { fileName = fileName.substring(base.length()); if (fileName.charAt(0) == '/') { fileName = fileName.substring(1); } else { ... |
String | getRelativePath(File baseDir, File subFile, String seperator) get Relative Path String basePath = baseDir.getAbsolutePath(); String filePath = subFile.getAbsolutePath(); if (!filePath.startsWith(basePath)) { return null; String relativePath = filePath.substring(basePath.length() + 1); return seperator == null ? relativePath : relativePath.replaceAll("\\\\", seperator).replaceAll("/", seperator); ... |
String | getRelativePath(File baseFile, File file) get Relative Path String basePath = ""; String path = ""; basePath = baseFile.getAbsolutePath(); path = file.getAbsolutePath(); if (!basePath.endsWith(File.separator)) { basePath = basePath + File.separator; if (path.indexOf(basePath) != 0) ... |
String | getRelativePath(File baseFolder, File subject) Helper function to get the relative path for subject starting at baseFolder return subject.getAbsolutePath().substring(baseFolder.getAbsolutePath().length() + 1);
|