Monday, February 25, 2008

Creating a directory path in Eclipse

The following snippet of code creates a folder structure in eclipse.
String directory = "ibn.soa.workingfolder";
String[] result = directory.split("\\.");
int k = result.length;
String e = "";
int i = 0;
while (i != k) {
e = e + result[i++] + "\\";
b = project.getFolder(".\\src\\" + e);
b.create(IResource.FORCE, true, null);
}

For example if you had the user enter something like "ibn.soa.workingfolder" and wanted to create that structure in eclipse you could use the above snippet. There are certain assumptions made, like you want it created in the src folder, but if you were looking for this kind of solution you probably know what those assumptions are by this point.
There is another way to do this using the eclipse Java Development Tooling ,JDT, framework but I didn't want to do it that way.

Labels: ,

6 Comments:

Blogger Kiat said...

Any reason you don't use the pre-made functions?

7:57 AM  
Blogger syed said...

What pre-made function?

8:33 AM  
Blogger ab said...

How did I miss this post earlier this week?

7:56 AM  
Blogger syed said...

You may have.

5:43 AM  
Blogger Kiat said...

I mean by using the JDT framework.

12:57 PM  
Anonymous Anonymous said...

SUCK IT SYED -- MY BOY'S JUST DESTROYED THE SPURS

1:50 AM  

Post a Comment

<< Home