This article mainly introduces the PHP implementation of bulk modification of file suffix name method, involving PHP recursive traversal and renaming of files related skills, with a certain reference value, the need for friends can refer
In this paper, we describe the method of PHP to implement batch modification of file suffix name. Share to everyone for your reference. Specific as follows:
/** * Bulk Modify file suffix name * @param $path folder path * @param $sext original file suffix ($sext =all all files throughout the directory) * @param $dext destination file suffix * @return void
*/function Foreachdir ($path, $sext, $dext) { $handle =opendir ($path); if ($handle) {while (false!== ($file = Readdir ($handle))) { if ($file! =). "&& $file! = ' ... ') { if (Is_dir ($path. $file)) { Foreachdir ($path. $file); } else{ $ext = Strripos ($file, '. '); $fileName = substr ($file, 0, $ext); $SRC = $path. ' /'. $file; $dest = $path. ' /'. $fileName. '. $dext; if ($sext! = "All") { if ($sext = = substr ($src, 0-strlen ($sext))) rename ($src, $dest); } else{ Rename ($src, $dest); }}} return false; } }foreachdir (' C:\Users\chenlinzhong\Desktop\redis-stable\src ', ' C ', ' txt ');