The code is as follows
Copy the codeThe code is as follows:
$dir = 'D:Program FilesresourceapplicationSkinPNG\';//Pay attention to the path here, add two at the end, the first one means change, but it is easy this way When encountering other specific escapes, you need to make careful judgments. You can write it as follows
$dir = 'D:/Program Files/resource/application/Skin/PNG/';//Writing a path like this, you don’t have to worry about escaping Problem. Don’t leave out the last one
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if ($file != ". " && $file != "..")
{
if(filetype($dir . $file) == 'file')
{
$newfile = str_replace(array('_PNG','_XML','_ICO '),array('.PNG','.XML','.ICO'), $file);
var_dump($file.' =======> '.$newfile.'
');
rename($dir . $file, $dir . $newfile);
}
}
}
closedir($dh);
}
The above introduces how to display file extensions and the implementation code for batch replacement of file names in PHP, including how to display file extensions. I hope it will be helpful to friends who are interested in PHP tutorials.