Name change for a large number of images

Source: Internet
Author: User
Tags glob
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.