百度上下的图片想重命名一下,命名为1,2,3,4…
程序运行前记得保存下源文件,以防万一。
public static void main(String[] args) {
// 想命名的原文件的路径
String file = "D:\\temp\\image_temp_wood";
folderMethod1(file);
}
public static void folderMethod1(String path) {
int fileNum = 0;
File file = new File(path);
LinkedList<File> list = new LinkedList<File>();
if (file.exists()) {
if (null == file.listFiles()) {
return;
}
list.addAll(Arrays.asList(file.listFiles()));
if (!list.isEmpty()) {
for (File f : list) {
fileNum++;
rename(f, fileNum);
}
}
}
}
public static void rename(File file, int fileNum) {
file.renameTo(new File(file.getParent() + "/" + fileNum + ".jpg"));
}
运行前:
运行后: