@@ -578,13 +578,49 @@ private static void doCopyFile(File srcFile, File destFile, boolean preserveFile
578578 }
579579
580580 //-----------------------------------------------------------------------
581+ /**
582+ * Copies a directory to within another directory preserving the file dates.
583+ * <p>
584+ * This method copies the source directory and all its contents to a
585+ * directory of the same name in the specified destination directory.
586+ * <p>
587+ * The destination directory is created if it does not exist.
588+ * If the destination directory did exist, then this method merges
589+ * the source with the destination, with the source taking precedence.
590+ *
591+ * @param srcDir an existing directory to copy, must not be null
592+ * @param destDir the directory to place the copy in, must not be null
593+ *
594+ * @throws NullPointerException if source or destination is null
595+ * @throws IOException if source or destination is invalid
596+ * @throws IOException if an IO error occurs during copying
597+ */
598+ public static void copyDirectoryToDirectory (File srcDir , File destDir ) throws IOException {
599+ if (srcDir == null ) {
600+ throw new NullPointerException ("Source must not be null" );
601+ }
602+ if (srcDir .exists () && srcDir .isDirectory () == false ) {
603+ throw new IllegalArgumentException ("Source '" + destDir + "' is not a directory" );
604+ }
605+ if (destDir == null ) {
606+ throw new NullPointerException ("Destination must not be null" );
607+ }
608+ if (destDir .exists () && destDir .isDirectory () == false ) {
609+ throw new IllegalArgumentException ("Destination '" + destDir + "' is not a directory" );
610+ }
611+ copyDirectory (srcDir , new File (destDir , srcDir .getName ()), true );
612+ }
613+
581614 /**
582615 * Copies a whole directory to a new location preserving the file dates.
583616 * <p>
584617 * This method copies the specified directory and all its child
585618 * directories and files to the specified destination.
586619 * The destination is the new location and name of the directory.
587- * If it already exists, the contents will be overwritten.
620+ * <p>
621+ * The destination directory is created if it does not exist.
622+ * If the destination directory did exist, then this method merges
623+ * the source with the destination, with the source taking precedence.
588624 *
589625 * @param srcDir an existing directory to copy, must not be null
590626 * @param destDir the new directory, must not be null
@@ -603,6 +639,7 @@ public static void copyDirectory(File srcDir, File destDir) throws IOException {
603639 * <p>
604640 * This method copies the contents of the specified source directory
605641 * to within the specified destination directory.
642+ * <p>
606643 * The destination directory is created if it does not exist.
607644 * If the destination directory did exist, then this method merges
608645 * the source with the destination, with the source taking precedence.
0 commit comments