Return to Snippet

Revision: 19054
at October 15, 2009 10:43 by dmautz1


Initial Code
<?
function copy_directory( $source, $destination ) {
	if ( is_dir( $source ) ) {
		@mkdir( $destination );
		$directory = dir( $source );
		while ( FALSE !== ( $readdirectory = $directory->read() ) ) {
			if ( $readdirectory == '.' || $readdirectory == '..' ) {
				continue;
			}
			$PathDir = $source . '/' . $readdirectory; 
			if ( is_dir( $PathDir ) ) {
				copy_directory( $PathDir, $destination . '/' . $readdirectory );
				continue;
			}
			copy( $PathDir, $destination . '/' . $readdirectory );
		}
 
		$directory->close();
	}else {
		copy( $source, $destination );
	}
}
?>

Initial URL

                                

Initial Description
Easily copy a folder to a new destination.

Initial Title
PHP Copy Source Folder to Destination

Initial Tags
php, copy

Initial Language
PHP