commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 36315] New: - add recursive directory copy
Date Tue, 23 Aug 2005 08:34:09 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=36315>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=36315

           Summary: add recursive directory copy
           Product: Commons
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: IO
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: flofh@gmx.de


Hi,

I needed a recursive copying of one directory to another.
Here's my source to do that:
/** Copies the source folder with its entire subtree into the destination 
folder.
 * So copyFolder(new File("/aaa"), new File("/bbb")) will create a folder /bbb/
aaa into which all the content of /aaa is copied.
 * In case /bbb/aaa already exists there's no exception etc.  
 * @param source A file or folder. Folders are copied with all their content. 
For files this method is equal to {@link FileUtils#copyFileToDirectory(java.io.
File, java.io.File)}.
 * @param destinationDirectory Where to copy the files and folders.
 * @throws IOException if any access problems or other IO issues occur during 
copying.
 */
public static void copyDirectoryToDirectory(File source, File 
destinationDirectory) throws IOException
{
	if (destinationDirectory.exists() && destinationDirectory.isFile())
		throw new IllegalArgumentException("The destinationDirectory must be a 
directory! destination = '" + destinationDirectory + "'");
	if (source.isFile())
		FileUtils.copyFileToDirectory(source, destinationDirectory);
	else
	{
		File copyDest = new File(destinationDirectory + File.separator + source.
getName());
		FileUtils.forceMkdir(copyDest);
		
		// recursive copy
		File[] files = source.listFiles();
		for (int i = 0; i < files.length; ++i)
			copyDirectoryToDirectory(files[i], copyDest);
	}
}

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message