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