Saturday, December 26, 2020

JAVA Code to Rename all files in a folder

JAVA Code to Rename all files in a folder


import java.io.*;

public class RenameFileNames 

{

     public static void main(String[] args) 

     {

        String absolutePath = "E:\\Wllpapers\\unbelive";

        File dir = new File(absolutePath);

        File[] filesInDir = dir.listFiles();

        int i = 0;

        for(File file:filesInDir) {

            i++;

            String name = file.getName();

            String newName = "pic" + i + ".jpeg";

            String newPath = absolutePath + "\\" + newName;

            file.renameTo(new File(newPath));

            System.out.println(name + " changed to " + newName);

        }

    }

}


6 comments:

  1. Wow, incredible blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is great, let alone the content! ufabet168

    ReplyDelete
  2. Nice information about android app development thanks for sharing this article.

    ReplyDelete
  3. Hi,
    Thanks for sharing the information with us it was very informative. Hangup.in

    ReplyDelete