How to batch modify file names in php

王林
Release: 2023-02-28 20:54:01
Original
3113 people have browsed it

How to batch modify file names in php

Can be modified in batches through the rename() function.

Function introduction:

The rename() function is used to rename files or directories.

Syntax format:

rename(oldname,newname,context)
Copy after login

If successful, this function returns TRUE. On failure, returns FALSE.

Example code:

将名为:".$fn."\n\r"; $curDir = $dirname.'/'.$fn; if(is_dir($curDir)){ fRename($curDir); }else{ $path = pathinfo($curDir); //改成你自己想要的新名字 $newname = $path['dirname'].'/'.$i.'.'.$path['extension']; echo "替换成:".$i.'.'.$path['extension']."\r\n"; rename($curDir,$newname); $i++; } } } } //给出一个目录名称可以是相对路径,也可以是绝对路径 fRename('img\Gastroenterology'); exit(); ?>
Copy after login

Some result screenshots are as follows:

How to batch modify file names in php

##For more related tutorials, please pay attention to

php Chinese website.

The above is the detailed content of How to batch modify file names in php. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!