Skip to content

Instantly share code, notes, and snippets.

@stephenjtong
Last active August 29, 2015 14:24
Show Gist options
  • Save stephenjtong/93e32a5793ce3000c94b to your computer and use it in GitHub Desktop.
Save stephenjtong/93e32a5793ce3000c94b to your computer and use it in GitHub Desktop.
random add num prefix to file
<?php
$files = scandir('.');
shuffle($files);
$i = 1;
foreach($files as $file){
if(preg_match('/^\./', $file)){
continue;
}
if(!preg_match('/(mp3|wav)$/', $file)){
continue;
}
$prefix = sprintf("%03d", $i);
if(preg_match('/__/', $file)){
rename($file, preg_replace('/^.*__/', $prefix.'__', $file));
}else{
rename($file, $prefix.'__'.$file);
}
$i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment