private void copyResults(File reportOutDir) throws IOException { List<File> resultDirectories = getResultsDirectories(); for (File directory : resultDirectories) { FileUtils.copyDirectory(directory, reportOutDir); } }
/** * Makes a copy of the given directory in the specified destination directory. * * @see #copyDirectory(File, File) */ public static void copyDirectoryToDirectory(@NonNull final File from, @NonNull final File to) throws IOException { copyDirectory(from, new File(to, from.getName())); }
/** * Copies a file or a directory's contents to another file or directory, which can have a * different name. The target file/directory is replaced if it already exists. * * <p>The source file/directory must exist and must not reside in, contain, or be identical to * the target file/directory. */ private static void copyFileOrDirectory(@NonNull File from, @NonNull File to) throws IOException { Preconditions.checkArgument( from.exists(), "Source path " + from.getAbsolutePath() + " does not exists."); Preconditions.checkArgument(!FileUtils.isFileInDirectory(from, to)); Preconditions.checkArgument(!FileUtils.isFileInDirectory(to, from)); Preconditions.checkArgument(!from.getCanonicalFile().equals(to.getCanonicalFile())); if (from.isFile()) { Files.createParentDirs(to); FileUtils.copyFile(from, to); } else if (from.isDirectory()) { FileUtils.deletePath(to); FileUtils.copyDirectory(from, to); } }