Skip to content

Instantly share code, notes, and snippets.

@lrepolho
Last active April 4, 2017 10:18
Show Gist options
  • Save lrepolho/ab522c66c9842642d281956c5a83b692 to your computer and use it in GitHub Desktop.
Save lrepolho/ab522c66c9842642d281956c5a83b692 to your computer and use it in GitHub Desktop.
Set filenames as it's equivalent SHA256
<?php
// usage: php renamefiles.php /path/to/dir
$photosDir = $_SERVER['argv']['1'];
$files = scandir($photosDir);
foreach ($files as $file) {
if ($file == '.' || $file == '..') {
continue;
}
$oldFile = "$photosDir$file";
$extension = pathinfo($oldFile, PATHINFO_EXTENSION);
$hash = hash_file('sha256', $oldFile);
$newFile = "$photosDir$hash.$extension";
rename($oldFile, $newFile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment