File batch naming in order (Windows+ubuntu)

Source: Internet
Author: User

Under Windows, you can use the MATLAB program to batch name all the files sequentially, take pictures as an example, the code is as follows:

Path = ' C:\Users\Administrator\Desktop\select_img\ ';% all pictures stored paths d = Dir ([path ' *.jpg ']);% reads all files under this path into a struct for i = 1: Length (d)% traverse each picture     image_name = D (i). name;% the name of each picture     i = Imread (strcat (path,image_name));% reads each picture     nz= strcat ('%0 ', NUM2STR (6), ' d ');% gives the picture the number of digits of the name     temp_id = sprintf (Nz,i), and the% is named for all pictures, preceded by 0     name2 = strcat (temp_id, '. jpg ');     Imwrite (i,name2);% save a picture with a new name end

Under Ubuntu You can use the terminal in the folder to enter the script program, all files in order to batch name, the script is as follows:

# first enter the following two lines of instruction, named for all files by ordinal, and to avoid conflicts with previous names (such as a number in the previous name), all the names followed by the letter a  -I. num=0;  for  in ' ls ';d o mv-f $name ' echo $num'a.jpg';  num=num+1#  again enter the following two lines of instruction, according to the serial number to re-name all files- i num=0;  for  in ' ls ';d o mv-f $name ' echo $num'. jpg'; num=num+1; Done

File batch naming in order (Windows+ubuntu)

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.