如何批量修改java文件包路径

2025-04-04 20:38:55
推荐回答(1个)
回答1:

public static void main(String[] args) {
updateFileNames("D:\\jjjj", "第");
}

public static void updateFileNames(String url, String index){
File file = new File(url);
//判断文件目录是否存在,且是文件目录,非文件
if(file.exists() && file.isDirectory()){
File[] childFiles = file.listFiles();
String path = file.getAbsolutePath();
for(File childFile : childFiles){
//如果是文件
if(childFile.isFile()){
String oldName = childFile.getName();
String newName = oldName.substring(oldName.indexOf(index));

childFile.renameTo(new File(path + "\\" + newName));
}
}
}

}