private static File join(File file, Object[] path) { File current = file.getAbsoluteFile(); for (Object p : path) { current = new File(current, p.toString()); } try { return current.getCanonicalFile(); } catch (IOException e) { throw new RuntimeException(String.format("Could not canonicalise '%s'.", current), e); } }
public void moveToDirectory(File target) { if (target.exists() && !target.isDirectory()) { throw new RuntimeException(String.format("Target '%s' is not a directory", target)); } try { FileUtils.moveFileToDirectory(this, target, true); } catch (IOException e) { throw new RuntimeException( String.format("Could not move test file '%s' to directory '%s'", this, target), e); } }
private void visit(Set<String> names, String prefix, File file) { for (File child : file.listFiles()) { if (child.isFile()) { names.add(prefix + child.getName()); } else if (child.isDirectory()) { visit(names, prefix + child.getName() + "/", child); } } }
public boolean isSelfOrDescendent(File file) { if (file.getAbsolutePath().equals(getAbsolutePath())) { return true; } return file.getAbsolutePath().startsWith(getAbsolutePath() + File.separatorChar); }
public void createLink(File target) { createLink(target.getAbsolutePath()); }