Before downloading a lot of video on the Internet, decompression, found inside each file has a long list of URLs, cause I can not see the name of each video exactly what is called?
Online Search Some batch renaming method, but is not what I want, since so, simply do it yourself with Java write a bar. The test should be no problem, share it now.
First code:
Import Java.io.File;
Import Java.util.HashMap;
Import Java.util.Map;
Import Java.util.Map.Entry; /** * Rename Rule class * @author Jack */class replacementchain{private map<string,string> Map; public Replacementchain () {T
His.map = new hashmap<string, string> (); String> Getmap () {return Map;//Add New replacement rule (string substitution) public Replacementchain addregulation (strin
G Oldstr, String newstr) {this.map.put (oldstr, NEWSTR); /** * Rename class * @author Jack/public class Rename {/** * Batch rename * @param path * @param replacementchain/public static VO ID multirename (String path,replacementchain replacementchain) {File File = new File (path); Boolean isdirectory = File.isdi
Rectory (); /** if it is not a folder, return */if (!isdirectory) {System.out.println (path +) is not a folder!
");
Return
} string[] files = file.list ();
File f = null;
String filename = ""; String oldfilename = "";
The previous name/** loops through all files * */for (String filename:files) {oldfilename = FileName; Map<string, String>
Map = Replacementchain.getmap (); For (entry<string, string> entry:map.entrySet ()) {fileName = Filename.replace (Entry.getkey (), Entry.getvalue ())
; } f = new File (path + "\" + oldfilename);
The output address and the original path remain consistent F.renameto (new File (path + "\" + fileName)); } System.out.println ("Congratulations, Batch renaming success!")
");
} public static void Main (string[] args) {}}
How to use:
If I now have a folder, which has a number of txt files, have a very long prefix and suffix.
Now I want to get rid of all their prefixes;
The first step is to create a new instance of the Replacementchain class in the Main method, which is a rule class. The main thing is to set up some substitution rules.
Replacementchain Replacementchain = new Replacementchain ();
Step two, add a replacement rule
Full name of first file:
"I am a good long prefix Oh" ~~~~~ novel 001 (I am the small tail of Meng Meng). txt
We want to take "I'm a good long prefix oh" ~~~~~ and (I am the small tail of Meng Meng) removed, just add two replacement rules on the Replacementchain.
Replacementchain.addregulation ("I am a good long prefix oh" ~~~~~ "," "). Addregulation (" I am the little tail of Meng Meng) "," "");
Addregulation supports chained calls.
Step three, call the batch rename method
Rename.multirename ("f:\\ Test Folder", Replacementchain);
Two parameters are passed, the first is the folder path where files need to be processed in batches, and the second is the Replacementchain object.
Run
Console if printed out: Congratulations, batch renaming success!
Then it means success.
My local files have been renamed in bulk:
The above is a small series to introduce the Java implementation of the file batch rename test available (compact version), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!