首页 > 开发 > PHP > 正文

php中批量替换文件名的实现代码

2024-05-04 22:02:57
字体:
来源:转载
供稿:网友

在PHP开发程序过程中,我们都会遇到批量替换文件名,很多时候,我们程序中的各种问题也是由于文件的原因造成的,那么php中批量替换文件名的实现代码大家知道吗?下面就让错新技术频道小编带你一起来了解一下吧!

代码如下

复制代码 代码如下:

$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);
}
以上就是php中批量替换文件名的实现代码,更多内容请继续关注错新技术频道其它相关文章!
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表