自定义批量文件名称功能
package cn.fspdfcy;
import java.io.File;
import java.util.Scanner;
public class Test01 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("提示:此自定义重命名文件规则为 前缀 + 序号升序(三位001-999) + 后缀");
System.out.print("请输入文件夹目录(建议复制):");
String path = sc.nextLine();
File file = new File(path);
String[] fileNames = file.list();
if (fileNames == null) {
System.out.println("路径输入错误或文件夹为空");
} else {
System.out.print("请输入自定义前缀:");
String prefixName = sc.nextLine();
System.out.print("请输入自定义后缀:");
String suffixName = sc.nextLine();
for (int i = 0; i < fileNames.length; i++) {
String oldName = fileNames[i];
String[] split = oldName.split("\\.");
String suffix = split[split.length - 1];
File file1 = new File(path + "/" + oldName);
String format = String.format("%03d", i+1);
String newName = prefixName + format + suffixName;
file1.renameTo(new File(path + "/" + newName + "." + suffix));
}
}
}
}
打包为可执行文件
- 新建Artifacts
- 选择入口
- Build Artifacts
- 复制jar包和jre到单独文件夹中
- 编写bat指定jre执行jar包
cmd /k ".\jre\bin\java.exe" -jar patchfilesname.jar
- 发给别人,解压执行bat,效果如下: