Refine search
String path = "/var/data/stuff/xyz.dat"; String base = "/var/data"; String relative = new File(base).toURI().relativize(new File(path).toURI()).getPath(); // relative == "stuff/xyz.dat"
private String getRelativePath(final Path targetPath) { return URI.create(this.rootUri.getPath()).relativize(targetPath.toUri()).getPath(); }
public static String convertToRelative(final Class clazz, final File f) { final File root = TestHelper.getRootOfBuildDirectory(clazz).getParentFile().getAbsoluteFile(); return root.toURI().relativize(f.getAbsoluteFile().toURI()).toString(); }
/** * {@inheritDoc} */ public String getName() { return root.getAbsoluteFile().toURI().relativize(file.getAbsoluteFile().toURI()).getPath(); }
private static File outputFileFor(File file, File baseDir, File outdir) { URI base = baseDir.getAbsoluteFile().toURI(); URI abs = file.getAbsoluteFile().toURI(); URI rel = base.relativize(abs); if (rel.isAbsolute()) { System.out.println("Cannot relativize " + file); return null; } URI outbase = outdir.toURI(); URI out = CodeGenUtil.resolve(outbase, rel); return new File(out); }
private String getBaseFileName(String string) { try { Path path = new Path(string); Path cursor = path.getParent(); while (partPattern.matcher(cursor.getName()).matches()) { cursor = cursor.getParent(); } return cursor.toUri().relativize(path.toUri()).getPath(); } catch (Exception ex) { // This could be due to either URI syntax error or File constructor // illegal arg; we don't really care which one it is. return string; } }
private String getRelativePath(final File targetFile) { return this.rootDirectory.toURI().relativize(targetFile.toURI()).getPath(); }
private static String relativeURIFor(File source, File target) { URI base = source.getAbsoluteFile().toURI(); URI abs = target.getAbsoluteFile().toURI(); // find common substring... URI commonBase = commonAncestor(base, abs); if (commonBase == null) return abs.toString(); URI baserel = commonBase.relativize(base); URI targetrel = commonBase.relativize(abs); if (baserel.isAbsolute() || targetrel.isAbsolute()) return abs.toString(); String prefix = ""; String sourceRel = baserel.toString(); for (int i = 0; i < sourceRel.length();) { i = sourceRel.indexOf('/', i); if (i < 0) break; prefix += "../"; i += 1; } return prefix + targetrel.toString(); }
@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attributes) { Path relative = Paths.get(base.relativize(dir.toUri()).getPath()); if (excludeMatcher.stream().anyMatch(pathMatcher -> pathMatcher.matches(relative))) { return FileVisitResult.SKIP_SUBTREE; } if (isParentIncluded.getOrDefault(dir.getParent(), false) || includeMatcher.stream().anyMatch(pathMatcher -> pathMatcher.matches(relative))) { isParentIncluded.put(dir, true); return FileVisitResult.CONTINUE; } return FileVisitResult.CONTINUE; }
File mydir = new File("C:\\mydir"); File myfile = new File("C:\\mydir\\path\\myfile.txt"); System.out.println(mydir.toURI().relativize(myfile.toURI()).getPath());
uri = new File(rawString).toURI(); uri = base.relativize(uri);
private boolean sidelineFile(FileSystem fs, Path hbaseRoot, Path path) throws IOException { URI uri = hbaseRoot.toUri().relativize(path.toUri()); if (uri.isAbsolute()) return false; String relativePath = uri.getPath(); Path rootDir = getSidelineDir(); Path dst = new Path(rootDir, relativePath); boolean pathCreated = fs.mkdirs(dst.getParent()); if (!pathCreated) { LOG.error("Failed to create path: " + dst.getParent()); return false; } LOG.info("Trying to sideline file " + path + " to " + dst); return fs.rename(path, dst); }
@Signature public static String relativize(String path, String base) { return new File(base).toURI().relativize(new File(path).toURI()).getPath(); }
URI currUri = files[i].toURI(); if (_baseDir != null && _baseDir.toURI().relativize(currUri).equals(currUri))
private String getBaseFileName(String string) { try { Path path = new Path(string); Path cursor = path.getParent(); while (partPattern.matcher(cursor.getName()).matches()) { cursor = cursor.getParent(); } return cursor.toUri().relativize(path.toUri()).getPath(); } catch (Exception ex) { // This could be due to either URI syntax error or File constructor // illegal arg; we don't really care which one it is. return string; } }
public static String getRelativePath(File base, File file) { return removeTrailingSlash(base.toURI().relativize(file.toURI()).getPath()); }
boolean myCheck(File maybeChild, File possibleParent) { URI parentURI = possibleParent.toURI(); URI childURI = maybeChild.toURI(); return !parentURI.relativize(childURI).isAbsolute(); }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException { Path relative = Paths.get(base.relativize(file.toUri()).getPath()); if (excludeMatcher.stream().anyMatch(pathMatcher -> pathMatcher.matches(relative))) { return FileVisitResult.CONTINUE; } if ((isParentIncluded.getOrDefault(file.getParent(), false) || includeMatcher.stream().anyMatch(pathMatcher -> pathMatcher.matches(relative))) && (file.toFile().getCanonicalPath().endsWith(".swift") && file.toFile().canRead())) { fileNames.add(file.toFile().getCanonicalPath()); } return FileVisitResult.CONTINUE; }
/** * Sets the path to the data directory. * * @param dataDir the path to the replica's data directory * @return the replica builder */ public Builder withDataDirectory(File dataDir) { config.getStorageConfig().setDirectory(new File("user.dir").toURI().relativize(dataDir.toURI()).getPath()); return this; }
private static String constructRelativeClasspathUri(File jarFile, File file) { URI jarFileUri = jarFile.getParentFile().toURI(); URI fileUri = file.toURI(); URI relativeUri = jarFileUri.relativize(fileUri); return relativeUri.getRawPath(); }