Reputation: 479
Is it possible to rename all the classes in package with a single command. Right now , My class names are like com.abc.Class1/com.abc.Class2. Now I am copying all these classes under a new package com.xyx....In class definition I have changed the names using "File search" ...So now How can I change the names under my package (One command for all classes under package "xyz").
Upvotes: 0
Views: 1859
Reputation: 349
Try some as this, move and then rename all files in a directory:
import java.io.File;
public class Ls {
public static void main(String args[])
{
String[] dir = new java.io.File("test").list();
java.util.Arrays.sort(dir);
File f[] = new File("test").listFiles();
int len1 = dir.length;
for (int i=0;i<len1; i++)
{
System.out.println(dir[i]);
String name = f[i].getName();
System.out.println(name);
int j=name.indexOf('.');
System.out.println(j);
String newname = name.substring(0,j) + "_BS" + name.substring(j,name.length());
System.out.println(newname);
File newFileName=new File(f[i].getParentFile(), newname);
System.out.println("newFileName="+newFileName);
f[i].renameTo(newFileName);
}
}
}
Upvotes: 2
Reputation: 61538
If I have understood correctly, you want to move our classes to another package. For this, click on the package in the project explorer and press Shift+Alt+R to rename it, effectively moving all included classes to the new package. This will not affect the names of the classes
EDIT A class name prefix? It's at least highly unusual. Eclipse can not help you with these. But if you are on a linux machine, you could do a mass move from command line. I am not fluent with it myself, so here is a mmv tutorial.
Upvotes: 2