不会直接使用Windows 的bat 批量修改文件名,所以就写了个JAVA程序,调用cmd.exe来实现批量修改文件名二话不说,可运行程序贴上。
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ReNameBat {
/**
*
文件名太长了,而且文件的个数很多,所以就写了个批量重命名的程序,如果手动修改的话,费时间!
原文件名字:动力节点_王勇_JAVA视频教程_Struts004_第一个Struts示例_回顾中午内容.zip
修改后的文件:Struts004_第一个Struts示例_回顾中午内容.zip
修改动作:就是讲【动力节点_王勇_JAVA视频教程_】去掉!
*/
public static String filePath = "F:\\教学视频\\动力节点_王勇_JAVA视频教程\\";
public static String needRm = "动力节点_王勇_JAVA视频教程_";
public static void o(Object o) {
System.out.println(o);
}
public static void reName() throws FileNotFoundException {
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File fileFolder = new File(filePath);
File[] files = fileFolder.listFiles();
//deal with only files,if a directory ,then miss it
if (!fileFolder.isDirectory()) {
for (File file : files) {
String fromFileName = file.getName();
String toFileName = "default";
if (fromFileName.contains(needRm)) {
String str[] = fromFileName.split(needRm);
toFileName = str[1];
Runtime.getRuntime().exec("cmd /c rename " + filePath + fromFileName + " "+ toFileName);
} else {
o(fromFileName);
}
}
}
}
}
有啥问题可以加微信聊:chenkunlia