public class Rename {
public static void main(String[] args) {
String path="";
File file = new File(path);
File[] list=file.listFiles();
//如果目录下存在文件
if (file.exists()&&file.isDirectory()){
for (int i=0;i<list.length;i++){
String name=list[i].getName();
//截取后缀之后的格式
int index2=name.lastIndexOf(".");
String name3=name.substring(index2);
//设置编号
String str=new DecimalFormat("0000").format(i+1);
String newName=str+name3;
//重命名
File dest = new File(path + "/" + newName);
list[i].renameTo(dest);
System.out.println(dest.getName());
}
}
}
}
简单的文件批量重命名
最新推荐文章于 2024-04-15 15:10:51 发布