package com;
import java.io.File;
public class ReFileName {
public static void findFile(String filePath) {
File file = new File(filePath);
String fn="";
char[] namePart;
String hzPart="";
String newName="";
if (file.isDirectory()) {
String[] fileDir = file.list();
String fileNameWithPath;
int aa=0;
for (int i = 0; i < fileDir.length; i++) {
fileNameWithPath = file.getAbsolutePath() + "\\" + fileDir[i];
String fileNewName = "";
System.out.println(i+" "+fileNameWithPath);
fn=fileDir[i];
hzPart=fn.substring(fn.indexOf("."));
namePart=fn.substring(0,fn.indexOf(".")).toCharArray();
for(int ii=0;ii if(checkChar(namePart[ii])){
System.out.println(newName);
aa=aa+1;
break;
}else{
newName=newName+String.valueOf(namePart[ii]);
}
}
File f = new File(fileNameWithPath);
f.renameTo(new File("d:\\1\\" + newName.trim()+hzPart));
newName="";
}
System.out.println("renName次数:"+aa);
} else {
}
}
public static boolean checkChar(char oneChar){
if((oneChar >= '\u4e00' && oneChar <= '\u9fa5')
||(oneChar >= '\uf900' && oneChar <='\ufa2d'))
return true;
return false;
}
/**
*
* @param args
*
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
findFile("D:/14");
}
}
阅读(6336) | 评论(0) | 转发(0) |