I was just trying to rename multiple folders inside a single directory. I thought of using Java code or perl script. but unfortunately I was only able to replace the string for only file names and not for folder names.
If anyone has done this earlier, please share the knowledge.
Example: I have below folders in a directory D:\MyDirectory\
Folder_is_A1
Folder_is_B1
Folder_is_C1
.
.
Folder_is_Z10
I'm trying to rename them as
Folder_A1
Folder_B1
.
.
Folder_Z10
Here is the code which I'm trying.
import java.io.File;
import java.util.Scanner;
public class RenameFoldersInDirectory{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the directory path");
String directoryPath = scanner.nextLine();
File directory = new File(directoryPath);
if (!directory.isDirectory()) {
System.err.println("There is no directory in the path given");
System.exit(0);
}
System.out.println("Enter new name of folder");
String newDirectoryName = scanner.nextLine();
File newDirectory = new File(directory.getParent() + "\\" + newDirectoryName);
directory.renameTo(newDirectory);
System.out.println("Done");
}
}