The img folder contains 1000 images. how can I change the names of these one thousand images to 1 to 1000 ???? {Code...} solves the problem of 1000 images in the img folder. how can I change the names of these one thousand images to 1 to 1000 ????
$ Arr = glob ("img /*. jpg "); var_dump ($ arr); $ I = 1; foreach ($ arr as $ file) {// get the image suffix $ ext = pathinfo ($ file, PATHINFO_EXTENSION ); $ name = $ I ++. ". ". $ ext; // rename ($ file, $ name );}
Solved
Reply content:
The img folder contains 1000 images. how can I change the names of these one thousand images to 1 to 1000 ????
$ Arr = glob ("img /*. jpg "); var_dump ($ arr); $ I = 1; foreach ($ arr as $ file) {// get the image suffix $ ext = pathinfo ($ file, PATHINFO_EXTENSION ); $ name = $ I ++. ". ". $ ext; // rename ($ file, $ name );}
Solved
Bash can be used. if you run php in linux and have bash, you can perform the following operations:shell_exec("i=1;for file in /path/to/img; do mv $file $i; i=$i+1; done")
Of course, there is actually a function named rename: rename php manual in php. you can:
$arr = scandir("/path/to/img");$i = 1;foreach($arr as $file) { rename($file, $i++);}
Note that the php version is correct.
// Obtain the image list $ arr = scandir ("/path/to/img"); $ I = 1; foreach ($ arr as $ file) {// get the image suffix $ ext = pathinfo ($ file, PATHINFO_EXTENSION); $ name = $ I ++. ". ". $ ext; // rename ($ file, $ name );}
You can see what js can be used for the js-like network structure recently released by Xin Xu.
The above code uses nodejs to change names in batches.