Sunday, 4 February 2018

Java program to rename files inside a directory

package renamefile;

package renamefile;

import java.io.File;

import java.io.IOException;
public class renamefile {

public static void main(String[] argv) throws IOException {
File folder = new File("C:\\Users\\Desktop\\Files\\");

File[] listOfFiles = folder.listFiles(); int count=0;

System.out.println("File Inside the folder are");

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {

count++;

File f = new File("C:\\Users\\Desktop\\Files\\"+listOfFiles[i].getName());  System.out.println("old name:"+f.getName());

f.renameTo(new File("C:\\Users\\Desktop\\Files\\"new_name"));                    System.out.println("New name:"+f.getName());

}

}

System.out.println("Total number of files renamed are :"+count);
} }

No comments:

Post a Comment

Handaling XLS File In Java

This code will help you to handle xls file in java using apache poi. package test; import java.io.File; import java.io.FileInputStream...