Home > Backend Development > PHP Tutorial > Implementation code for batch replacement of file names in php

Implementation code for batch replacement of file names in php

高洛峰
Release: 2023-03-01 12:22:02
Original
1501 people have browsed it

The code is as follows:
$dir = 'D:Program FilesresourceapplicationSkinPNG\';//Pay attention to the path here, add two at the end, the first one represents the escape, but it is easy to encounter other specific escapes, so you need to judge carefully , can be written as follows
$dir = 'D:/Program Files/resource/application/Skin/PNG/';//Write such a path, you don't have to worry about escaping. Don’t omit the last/don’t write
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);
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template