package com.test;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class RenameFiles {
public final String RDR ="[RDR]";
public final String ACD ="[ACD]";
public void ChangeFileName(File file){
String dirPath = file.getAbsolutePath();//目录路径
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
SimpleDateFormat df=new SimpleDateFormat("MMdd");
String style = df.format(date);
if(file.isDirectory()){
File[] files =file.listFiles();
for(File f: files){
String originalName = f.getName();
String toFileName = dirPath+"\\"+style + RDR +originalName;
File finalName = new File(toFileName);
f.renameTo(finalName);
}
}
}
public static void main(String[] args) {
File file = new File("E:\\1");
new RenameFiles().ChangeFileName(file);
}
}
java批量修改文件名字
最新推荐文章于 2024-08-15 14:47:41 发布