List of utility methods to do Path Relative Get
String | getRelativePath(File file, File folder) get Relative Path String filePath = file.getAbsolutePath(); String folderPath = folder.getAbsolutePath(); if (filePath.startsWith(folderPath)) { return filePath.substring(folderPath.length() + 1); } else { return null; |
String | getRelativePath(File file, File root) Strips off the part of the path before the start of the root file. int rootLength = root.getAbsolutePath().length(); String absolutePath = file.getAbsolutePath(); String relativePath = absolutePath.substring(rootLength + 1); return relativePath; |
String | getRelativePath(File file, File root) Si root="/export/share-img y file="/export/share-img/2009/03/01/file.txt" esto devuelve la cadena de caracteres "/2009/03/01/file.txt". if (root == null) { return file.getAbsolutePath(); if (file == null) { return null; String rootAbsolutePath = root.getAbsolutePath(); String fileAbsolutePath = file.getAbsolutePath(); ... |
String | getRelativePath(File file, File srcDir) Returns the relative path. String base = srcDir.getPath(); String filePath = file.getPath(); String relativePath = new File(base).toURI().relativize(new File(filePath).toURI()).getPath(); return relativePath; |
String | getRelativePath(File file, String xmlDirectoryPath) Returns a part of absolute path that starts from the xml directory path (xml directory path is cut off). return removeLeadingSlashes(file.getAbsolutePath().substring(xmlDirectoryPath.length()));
|
String | getRelativePath(File fileOrFolder, File baseFolder) get Relative Path if (!baseFolder.isDirectory()) baseFolder = baseFolder.getAbsoluteFile().getParentFile(); return baseFolder.toURI().relativize(fileOrFolder.toURI()).getPath(); |
String | getRelativePath(File folderContainingFile, File fileInFolder) get Relative Path String filePath = fileInFolder.getCanonicalPath(); String folderPath = folderContainingFile.getCanonicalPath(); return new File(folderPath).toURI().relativize(new File(filePath).toURI()).getPath(); |
String | getRelativePath(File fromDir, File toFile) get the path to a given file relative to a given directory String fromStr = fromDir.getAbsolutePath(); if (!fromStr.endsWith(File.separator)) { fromStr = fromStr + File.separator; String toStr = toFile.getAbsolutePath(); int pos = fromStr.indexOf(File.separator); int fromLen = fromStr.length(); int toLen = toStr.length(); ... |
String | getRelativePath(File fromFile, File toFile) Calculates the relative path between two files. String fromPath = fromFile.getCanonicalPath(); String toPath = toFile.getCanonicalPath(); String[] fromPathStack = getPathStack(fromPath); String[] toPathStack = getPathStack(toPath); if (0 < toPathStack.length && 0 < fromPathStack.length) { if (!fromPathStack[0].equals(toPathStack[0])) { return getPath(Arrays.asList(toPathStack)); } else { return getPath(Arrays.asList(toPathStack)); int minLength = Math.min(fromPathStack.length, toPathStack.length); int same = 1; for (; same < minLength && fromPathStack[same].equals(toPathStack[same]); same++) { List relativePathStack = new ArrayList(); for (int i = same; i < fromPathStack.length; i++) { relativePathStack.add(".."); for (int i = same; i < toPathStack.length; i++) { relativePathStack.add(toPathStack[i]); return getPath(relativePathStack); |
String | getRelativePath(File fromFile, File toFile) get Relative Path if (toFile != null) { ArrayList<File> lst = getParents(fromFile, null); if (fromFile.isDirectory()) { lst.add(fromFile); File rootFile = getRoot(toFile, lst); if (rootFile != null) { String ret = toRoot(rootFile, fromFile) ... |