Home > Backend Development > PHP Tutorial > PHP method to rename all files in a folder

PHP method to rename all files in a folder

墨辰丷
Release: 2023-03-26 13:42:02
Original
1974 people have browsed it

This article mainly introduces the method of renaming all files under a folder in PHP, involving PHP's related operation skills such as traversing, string search, interception and renaming files under the folder, etc., which requires Friends can refer to the following details:

<?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

Related recommendations:

node’s files are batch-reproduced Naming

Detailed explanation of node.js file upload, renaming and moving position

The above is the detailed content of PHP method to rename all files in a folder. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template