批量修改文件的名字

如图:

 

 

 

 

 需要去掉"副本",或者"的副本"2个字

public static void main(String [] args) {
        String dir="D:\\img\\product\\";
        File file = new File(dir);
        File[] f1s = file.listFiles();
        String absolutePath = file.getAbsolutePath();
        for (File f1 : f1s) {
            if(f1.getName().indexOf("副本")!=-1){
                String name = f1.getName();
                name=name.replace("副本","");
                if(name.indexOf("的")!=-1){
                    name=name.replace("的","");
                }
                f1.renameTo(new File(absolutePath,name));
            }
        }

结果如图:

 

posted @ 2019-10-24 16:35  yangxiaohui227  阅读(176)  评论(0编辑  收藏  举报