Last active
March 28, 2017 04:38
-
-
Save wsams/9c540a56306f2bc96d4bd356f5881129 to your computer and use it in GitHub Desktop.
A script to rename folders output from DateTree. Directories like 2017-03-27 would be renamed 20170327NikonDump. If that directory exists the contents of 2017-03-27 would be moved into it and deleted.
This file contains 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 | |
$suffix = "NikonDump"; | |
$dirs = glob("*", GLOB_ONLYDIR); | |
foreach ($dirs as $k=>$dir) { | |
$dumpdir = preg_replace("/^(\d{4})-(\d{2})-(\d{2})$/", "\${1}\${2}\${3}{$suffix}", $dir); | |
// Uncomment this line if you are only import new directories of the $suffix type. | |
// So if you imported everything from a Nikon camera then you can just uncomment | |
// this rename because all of the photos would be new. You also have to make sure all | |
// of the dates of these photos are new and that no existing directory exists. | |
//rename($dir, $dumpdir); continue; | |
if (preg_match("/^\d{4}-\d{2}-\d{2}$/", $dir)) { | |
if (file_exists($dumpdir)) { | |
$cmd = "mv {$dir}/* {$dumpdir}/"; | |
print("{$cmd}\n"); | |
system($cmd); | |
$cmd = "rmdir {$dir}"; | |
print("{$cmd}\n"); | |
system($cmd); | |
} | |
} else { | |
rename($dir, $dumpdir); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment