Skip to content

Instantly share code, notes, and snippets.

@Kovah
Created June 25, 2022 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kovah/ed9851cd020448215d86cade3b663c55 to your computer and use it in GitHub Desktop.
Save Kovah/ed9851cd020448215d86cade3b663c55 to your computer and use it in GitHub Desktop.
<?php
// Randomizes the names of all files in the current directory
// Use with caution!
$files = scandir(__DIR__);
$files = array_filter($files, fn($file) => !in_array($file, ['.', '..', 'randomize.php', '.DS_Store']));
echo 'Renaming ' . count($files) . 'files now';
shuffle($files);
foreach ($files as $file) {
$new = hash('crc32', $file) . time() . '.' . pathinfo($file, PATHINFO_EXTENSION);
var_dump("Renaming $file to $new");
rename(__DIR__ . '/' . $file, __DIR__ . '/' . $new);
}
echo 'Done';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment