public static void copyDirectory(File source, File destination) throws IOException { copyDirectory(source, destination, null); }
public static void copyDirectory(File source, File destination, FileFilter filter) throws IOException { File nextDirectory = new File(destination, source.getName()); // // create the directory if necessary... // if (!nextDirectory.exists() && !nextDirectory.mkdirs()) { Object[] filler = { nextDirectory.getAbsolutePath() }; String message = _MESSAGES.get("DirCopyFailed", filler); throw new IOException(message); } File[] files = source.listFiles(); // // and then all the items below the directory... // for (int n = 0; n < files.length; ++n) { if (filter == null || filter.accept(files[n])) { if (files[n].isDirectory()) copyDirectory(files[n], nextDirectory, filter); else copyFile(files[n], nextDirectory); } } }
copyDirectory(source, destination);