List of utility methods to do Path Relative nio
String | relativePath(String input, String mainurl) Compute sub directory of given input, relative to main module. Path inputPath = Paths.get(input);
Path rootPath = Paths.get(mainurl);
Path relativize = rootPath.getParent().relativize(inputPath.getParent());
return relativize.toString();
|
String | relativePathTo(Path path, Path basePath) relative Path To if ("index.html".equalsIgnoreCase(path.getFileName().toString())) { path = path.getParent(); if (!java.nio.file.Files.isDirectory(basePath)) { basePath = Optional.ofNullable(basePath.getParent()).orElse(basePath); String relUrl = basePath.relativize(path).toString(); return "".equals(relUrl) ? "." : relUrl; ... |
Path | relativize(Path absoluteDirectory, Path subDirectory) relativize return absoluteDirectory.relativize(subDirectory.toAbsolutePath().normalize());
|
List | relativize(Path target, Collection relativize List<Path> relativizedPaths = new ArrayList<>(); for (Path path : paths) { relativizedPaths.add(target.relativize(path)); return relativizedPaths; |
String | relativizeAndNormalizePath(final String baseDirectory, final String path) Constructs a normalized relative path between base directory and a given path. if (baseDirectory == null) { return path; final Path pathAbsolute = Paths.get(path).normalize(); final Path pathBase = Paths.get(baseDirectory).normalize(); return pathBase.relativize(pathAbsolute).toString(); |
IPath | relativizePath(IPath path, IPath basePath) Returns the relative path of the original path with respect to the basePath if they share the same prefix path, otherwise path is returned unchanged.
if (path == null) { return basePath; if (basePath == null) { return path; java.nio.file.Path base = basePath.toFile().toPath().toAbsolutePath(); java.nio.file.Path child = path.toFile().toPath().toAbsolutePath(); ... |
IPath | relativizePath(IPath path, IPath basePath, boolean strict) relativize Path if (path == null) { return basePath; if (basePath == null) { return path; java.nio.file.Path base = basePath.toFile().toPath().toAbsolutePath(); java.nio.file.Path child = path.toFile().toPath().toAbsolutePath(); ... |
String | relativizePath(Path root, Path child) relativize Path String childPath = child.toAbsolutePath().toString(); String rootPath = root.toAbsolutePath().toString(); if (childPath.equals(rootPath)) { return ""; int indexOfRootInChild = childPath.indexOf(rootPath); if (indexOfRootInChild != 0) { throw new IllegalArgumentException( ... |
String | relativizePath(String basePath, File toRelativize) This method has been deprecated use the Java Path relativize method instead. if (toRelativize == null) { return null; if (basePath == null || !toRelativize.getPath().startsWith(basePath)) { return toRelativize.getPath(); Path path = FileSystems.getDefault().getPath(basePath); Path relativePath = path.relativize(toRelativize.toPath()); ... |
String | resolvePathIfRelativeTo(File referenceFile, String partialPath) resolve Path If Relative To if (partialPath.startsWith("..") || partialPath.startsWith(".")) { String definitionOriginDir = referenceFile.getParentFile().getAbsolutePath(); partialPath = Paths.get(definitionOriginDir, partialPath).toAbsolutePath().toString(); return partialPath; |