Batch renaming of Files: initial code and batch renaming

Source: Internet
Author: User

Batch renaming of Files: initial code and batch renaming

A tool class is created to modify file names in batches. It can be used to download TV series online. If the name is not required for a website address, you can change it to the name you want in batches.

For example, if you have downloaded zookeeper from the Internet for 72 sets

The results are all named "http: // isoivjsvlkfdjorwiu pijklsjvgoij; lkjioju Episode 1" (garbled)

"Http: // isoivjsvlkfdjorwiu pijklsjvgoij; lkjioju second set" and so on;

You can batch change it to "batch Upload first set" "batch upload second set", etc.

1 package gaiming; 2 3 import java. io. file; 4 import java. util. authorization; 5 6 public class GaiMing {7 public void gai () {8 // remind you to enter the path of the renamed file directory 9 System. out. println ("Enter the path:"); 10 // Scanner 11 temperature input = new temperature (System. in); 12 // get the directory path 13 File file = new File (input. nextLine (); 14 // obtain the File path under the directory 15 file [] file1 = File. listFiles (); 16 // remind you to enter the file name field 17 System. out. println ("Enter the same characters in the content to be renamed:"); 18 String s1 = input. nextLine (); 19 // reminds you to enter the field 20 System for the new file name to be modified. out. println ("Enter the format to be modified"); 21 String s2 = input. nextLine (); 22 // loop renamed 23 for (int I = 0; I <file1.length; I ++) {24 // convert the file path to String type 25 String str = file1 [I]. toString (); 26 // determines whether the string contains the field to be modified 27 if (str. contains (s1) {28 // create a temporary String to save the replaced String type path 29 String sLS = str. replace (s1, s2); 30 // change the modified string type path to the abstract path 31 File fileLS = new File (sLS ); 32 // change the file to the file name provided by the abstract path 33 file1 [I]. renameTo (fileLS); 34} 35} 36} 37}

 

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.