You can pack cygwin as a tar package. Then, if the file is faulty
Java
Iconv-f gbk-T UTF-8 2010-10-30.txt-O 2010-10-30.txt
C
Iconv-f gbk-T UTF-8 2010-10-30.txt> 2010-10-30.txt
If there are multiple problems with files, implement them recursively.
The details are as follows:
Import java. Io. file;
Import java. Io. ioexception;
Import java. util. collections;
Import java. util. RegEx. pattern;
Public class changefile4zh {
Private Static int Total = 0;
Public static void main (string ARGs []) {
System. Out. println ("Enter the chat root folder :");
Pipeline SC = new pipeline (system. In );
String filepath = SC. nextline ();
If (filepath! = NULL & filepath. Length ()> 0 ){
Changefilename (filepath );
}
}
Public static void changefilename (string filepath ){
If (Total % 50 = 0) {system. Out. println ("Total:" + total );}
File file = new file (filepath );
If (file. exists ()){
File [] fileslist = file. listfiles ();
For (file F: fileslist ){
If (F. isfile ()){
// Rename the file
Renamefile (F. getabsolutepath (), F. getparent (), F. getname ());
Total ++;
} Else {
Changefilename (F. getabsolutepath ());
}
}
}
}
Public static void encode (string filepath ){
If (Total % 50 = 0) {system. Out. println ("Total:" + total );}
File file = new file (filepath );
If (file. exists ()){
File [] fileslist = file. listfiles ();
For (file F: fileslist ){
If (F. isfile ()){
// Recompile the File Content
Enconderfile (f );
Total ++;
} Else {
Encode (F. getabsolutepath ());
}
}
}
}
Public static void Delete (string filepath ){
If (Total % 50 = 0) {system. Out. println ("Total:" + total );}
File file = new file (filepath );
If (file. exists ()){
File [] fileslist = file. listfiles ();
For (file F: fileslist ){
If (F. isfile ()){
// Delete the original file
Deletefile (F. getabsolutepath (), F. getname ());
Total ++;
} Else {
Delete (F. getabsolutepath ());
}
}
}
}
Public static void enconderfile (File file ){
Runtime runtime = runtime. getruntime ();
Try {
Runtime.exe C ("iconv-f gbk-T UTF-8" + file. getpath () + "-o" + file. getparent () + file. separator + "Bak" + file. getname ());
} Catch (exception e ){
System. out. println ("iconv-f gbk-T UTF-8" + file. getpath () + "-o" + file. getparent () + file. separator + "Bak" + file. getname ());
}
}
Public static void renamefile (string realpath, string path, string filename ){
If (filename. startswith ("Bak ")){
Runtime runtime = runtime. getruntime ();
Try {
Runtime.exe C ("mv" + realpath + "" + path + file. Separator + filename. replacefirst ("Bak ",""));
} Catch (ioexception e ){
System. Out. println ("mv" + realpath + "" + path + file. Separator + filename. replacefirst ("Bak ",""));
}
}
}
// Delete an object
Public static void deletefile (string realpath, string filename ){
String regpath = "^ [// D] {4}-[// D] {2}-[// d1_1_22.16.txt $ ";
Pattern Pa = pattern. Compile (regpath );
If (Pa. matcher (filename). Find ()){
New file (realpath). Delete ();
}
}
}