Last active
August 29, 2015 14:24
-
-
Save stephenjtong/93e32a5793ce3000c94b to your computer and use it in GitHub Desktop.
random add num prefix to file
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 | |
$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