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(' '=>'_'); $newName = strtr($entry,$table_change); $newName = substr($newName, 0,-4); rename($paths.$entry, $paths.$newName."_s.jpg"); } $d->close(); echo "done"; ?>
The above is the detailed content of Introduction to how to batch rename all files in a folder with PHP. For more information, please follow other related articles on the PHP Chinese website!