<?php$dir = '/media/miku/9016-4EF8/' ;function filesInDir ($dir){$map = [];if ($desc = opendir($dir)){while ( false !== ($file = readdir($desc))){if ($file == '.' OR $file =='..' ){continue;}$path = rtrim($dir,'/' ).'/' .$file;if (is_file($path)){$map[] = $path;}elseif (is_dir($path)){$map = array_merge($map, filesInDir($path));}}closedir($desc);return $map;}}foreach (filesInDir($dir)as $file){$fileName = explode( '/' , $file);$fileName = $fileName{sizeof($fileName) - 1 };if (rename($file, rtrim($dir, '/' ). '/' .$fileName. '.ext' )){echo $fileName, ' RENAME OK<br>' ;}else{echo $fileName, ' RENAME ERROR<br>' ;}}