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

PHP method to rename all files in a folder

墨辰丷
墨辰丷Original
2018-05-18 10:37:341895browse

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

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!

Statement:
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