How to batch modify the names of all files in a folder in php

黄舟
Release: 2023-03-15 18:12:01
Original
2491 people have browsed it

This article mainly introduces PHP's method of batch renaming all files in a folder, involving PHP's related operation skills such as traversing files under the folder, string search, interception, and renaming files with the rename function. Friends who need it can refer to

This article describes the method of batch renaming all files in a folder in PHP. I share it with you for your reference. The details are as follows:

It’s tiring to manually rename one by one like this. So let’s be lazy.

My renaming rule is to replace all spaces with "_", and then add an "_s" after it.


<?php
$paths = "C://Documents and Settings//sk//Desktop//s//";
$d = dir($paths);
while (false !== ($entry = $d->read())) {
  $table_change = array(&#39; &#39;=>&#39;_&#39;);
  $newName = strtr($entry,$table_change);
  $newName = substr($newName, 0,-4);
  rename($paths.$entry, $paths.$newName."_s.jpg");
}
$d->close();
echo "done";
?>
Copy after login

The above is the detailed content of How to batch modify the names of all files in a folder 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template