代码如下
复制代码 代码如下:
$dir = 'd:\program files\resource\application\skin\png\\';//注意这里的路径,最后要加两个,第一个表示转意,但是这样容易遇到其他特定转义,还要仔细判断,可以写为如下方式 
$dir = 'd:/program files/resource/application/skin/png/';//写成这样的路径,就不用担心转义问题了。最后面的/不要漏写 
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); 
}
   
 
   