Following CI framework function does bulk rename of a given folder.
public function rename_id_names_of_images(){
$dir_path = 'C:\xampp\htdocs\myprojects\image_downloader\images\by_external_id';
if ($handle = opendir($dir_path)) {
$i=0;
while (false !== ($fileName = readdir($handle))){
// Get extension
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
$new_id = "name-$i";
$new_file_name = "$new_id.$ext";
echo "Old::$fileName==New::$new_file_name<br>";
rename("$dir_path/$fileName", "$dir_path/$new_file_name");
$i++;
}
closedir($handle);
echo "file count: $i";
}
}
Comments
Post a Comment