Created
January 25, 2020 15:11
-
-
Save alex-phillips/19922cd434f71f53eaf07af75355c31e to your computer and use it in GitHub Desktop.
recursively copy files form one dir to another - case insensitive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$src = $argv[1]; | |
$dest = $argv[2]; | |
if (!$src || !$dest) { | |
die("Need a source and destination"); | |
} | |
$src = rtrim($src, '/') . "/"; | |
$dest = rtrim($dest, '/') . "/"; | |
$files = getDirContents($src, $src); | |
$existing = getDirContents($dest, $dest); | |
foreach ($files as $file => $fullFile) { | |
if (array_key_exists($file, $existing)) { | |
echo "$fullFile => {$existing[$file]}\n"; | |
rename($fullFile, $existing[$file]); | |
} | |
} | |
function getDirContents($dir, $replace, &$results = array()){ | |
$files = scandir($dir); | |
foreach($files as $key => $value){ | |
$path = realpath($dir.DIRECTORY_SEPARATOR.$value); | |
if(!is_dir($path)) { | |
$results[strtolower(str_replace($replace, '', $path))] = $path; | |
} else if($value != "." && $value != "..") { | |
getDirContents($path, $replace, $results); | |
} | |
} | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment