/** * Copies a directory from one location to another */ public static void copyDirectory(String src, String dest, String... namesToIgnore) throws IOException { copyDirectory(new File(src), new File(dest), namesToIgnore); }
/** * Copies a files from one location to another. Overwriting any existing file at the destination. */ public static File copyFile(String in, String out) throws IOException { return copyFile(new File(in), new File(out)); }
/** * Copies a files from one location to another. Overwriting any existing file at the destination. */ public static File copyFileToDir(String in, String out) throws IOException { return copyFileToDir(new File(in), new File(out)); }
File src = FileUtil.normalize(src_); File dest = FileUtil.normalize(dest_); copyDirectory(srcFile, destFile, namesToIgnore); copyFile(src, dest);
return doNormalize(filename, SYSTEM_SEPARATOR, false);
/** * @return true if the named file is a zip/jar file */ public static boolean isZipFile(String fileName) { if (fileName == null) { throw new IllegalArgumentException("fileName cannot be null"); } return isZipFile(new File(fileName)); }
/** * Deletes a file or directory and all files and sub-directories under it. * * @param fileNamesToIgnore if prefaced with a '/', it will ignore as a directory instead of file * @return true iff the file/dir was deleted */ public static boolean delete(String fileName, String... fileNamesToIgnore) { if (fileName == null) { throw new IllegalArgumentException("fileName cannot be null."); } return delete(new File(fileName), fileNamesToIgnore); }
/** * Gets the relative path of a file to a specific directory in it's hierarchy. * <p/> * For example: getChildRelativeToDir("/a/b/c/d/e.bah", "c") -> "d/e.bah" */ public static String getChildRelativeToDir(String fileName, String dirInHeirarchy) { if (fileName == null || fileName.isEmpty()) { throw new IllegalArgumentException("fileName cannot be null."); } return getChildRelativeToDir(new File(fileName), dirInHeirarchy); }
/** * Gets the PARENT relative path of a file to a specific directory in it's hierarchy. * <p/> * For example: getParentRelativeToDir("/a/b/c/d/e.bah", "c") -> "/a/b" */ public static String getParentRelativeToDir(String fileName, String dirInHeirarchy) { if (fileName == null || fileName.isEmpty()) { throw new IllegalArgumentException("fileName cannot be null."); } return getParentRelativeToDir(new File(fileName), dirInHeirarchy); }
return 2; // return a length greater than the input return isSeparator(ch0) ? 1 : 0; ch0 = Character.toUpperCase(ch0); if (ch0 >= 'A' && ch0 <= 'Z') { if (len == 2 || isSeparator(filename.charAt(2)) == false) { return 2; else if (isSeparator(ch0) && isSeparator(ch1)) { int posUnix = filename.indexOf(UNIX_SEPARATOR, 2); int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2); return isSeparator(ch0) ? 1 : 0;
int prefix = getPrefixLength(filename); if (prefix < 0) { return null;
String normalizeNoEndSeparator(String filename, boolean unixSeparator) { char separator = unixSeparator ? UNIX_SEPARATOR : WINDOWS_SEPARATOR; return doNormalize(filename, separator, false);
return doNormalize(filename, SYSTEM_SEPARATOR, true);
/** * Copies a files from one location to another. Overwriting any existing file at the destination. * If the out file is a directory, then the in file will be copied to the directory */ public static File copyFileToDir(File in, File out) throws IOException { if (in == null) { throw new IllegalArgumentException("in cannot be null."); } if (out == null) { throw new IllegalArgumentException("out cannot be null."); } // copy the file to the directory instead if (!out.isDirectory()) { throw new IOException("Out file is not a directory! '" + out.getAbsolutePath() + "'"); } return copyFile(in, new File(out, in.getName())); }
String normalize(String filename, boolean unixSeparator) { char separator = unixSeparator ? UNIX_SEPARATOR : WINDOWS_SEPARATOR; return doNormalize(filename, separator, true);
return doNormalize(new File(filename).getAbsolutePath(), SYSTEM_SEPARATOR, true);
String asString = doNormalize(file.getAbsolutePath(), SYSTEM_SEPARATOR, true); if (asString == null) { return null;