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 );
}
}
this is my script for copy whole dirs and files to another destination. But i have small problem
My folders are like:
cinch.v2.1.1\cinch\cinch\other folders and files
loopy.v2.1.3\loopy\loopy\other folders and files
musy.v3.1.4\musy\musy\other folders and files
...
i need to copy just last (depth 3) cinch, loopy, musy folder with subfolders and files and not whole structure. How to change the script.
and copy structure should looks like this:
cinch\other folders and files
loopy\other folders and files
musy\other folders and files
I start with
if (strpos($readdirectory, '.') === false && strpos($readdirectory, '_') === false) {
but this not working as it must.
You must first look for level 3 directories and then copy these to your destination: