This article describes the Java implementation of file renaming method. Share to everyone for your reference. Specifically as follows:
The movies that are downloaded always have some useless information such as the existence of a website name as a OCD patient must remove them
Package sys.file;
Import java.util.*;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;
Import java.io.*;
public class Zrename {public static void main (String args[]) {zrename r = new Zrename ();
R.replace ();
R.changeorder ();
The public void replace () {file dir = new file ("g://movie//The rabbit that year [original picture version]");
Here write the alternate folder path, note the use of double slash string[] files = dir.list ();
File f = null;
String filename = "";
String oldname = "[Movie Heaven www.dygod.cn]"; String oldname = ""; The part String newName = "" To be replaced in the name;
The name to be replaced in the form of NULL for deletion for (String file:files) {f = new file (dir, file);
Note that here must be written as file (Fl,file) if written file (file) is not workable, must be full path filename = F.getname ();
SYSTEM.OUT.PRINTLN (filename); String s1= "\\d{4}.
(Youku | Sohu video)-";
Zrename r = new Zrename ();
Boolean B = r.regex1 (S1, filename);
Oldname = R.regex (S1, filename);
if (b) {//f.renameto (New File (Fl.getabsolutepath () + "//" +filename.replace ("content to be replaced", "replaced by")); You can use replace replacement again and again, but you can also use regularexpression to replace//Here you can use replace replacement again and again, but you can also use regular expressions to replace F.renameto (new File (Dir.getabsolutepath () + "//" + Filename.replace) (o
Ldname, NewName));
Deletes the front x bit//f.renameto (New File (Dir.getabsolutepath () + "//" + filename.substring (9)));
} system.exit (0);
public void Changeorder () {File dir = new File ("g://merge");
Here write the alternate folder path, note the use of double slash string[] files = dir.list ();
File f = null;
String filename = "";
String oldname = "[Movie Heaven www.dygod.cn]"; String oldname = ""; The part String newName = "" To be replaced in the name;
The name to be replaced in the form of NULL for deletion for (String file:files) {f = new file (dir, file);
Note that here must be written as file (Fl,file) if written file (file) is not workable, must be full path filename = F.getname ();
SYSTEM.OUT.PRINTLN (filename);
String s1= "\\d+";
Zrename r = new Zrename ();
Boolean B = r.regex1 (S1, filename);
oldname = filename;
NewName = R.regex (S1, filename) + "" +filename; if (b) {//f.renameto (New File (Fl.getabsolutepath () + "//" +filename.replace ("content to be replaced", "replaced by"))//can be reused hereEplace Replace, of course, you can also use regular expressions to replace///replace replacement with replace, of course, you can also use regular expressions to replace F.renameto (new File (Dir.getabsolutepath () + "//" +
Filename.replace (Oldname, newName));
Deletes the front x bit//f.renameto (New File (Dir.getabsolutepath () + "//" + filename.substring (9)));
} system.exit (0);
//s1 the regular expression to find, S2 find source public String regex (String s1,string S2) {Pattern p = pattern.compile (S1);
Matcher m = P.matcher (S2);
Boolean result = M.find ();
SYSTEM.OUT.PRINTLN (result);
String S = "";
if (result) {S = M.group ();
System.out.println (S);
return S;
//s1 the regular expression to find, S2 lookup Source public boolean regex1 (String s1,string S2) {Pattern p = pattern.compile (S1);
Matcher m = P.matcher (S2);
Boolean result = M.find ();
SYSTEM.OUT.PRINTLN (result);
return result;
}
}
I hope this article will help you with your Java programming.