I want to be able to pass a string of something like "page.tab" and based on this string i want my java program to scan through the current project in my Workspace and then search for all the files whose package name contain "page.tab". Whenever it finds such a package name, it should fill all the files under such a package in a Set and return.
Looks like you need some recursive algorithm. Working with files and directories will most likely need to work with the java.io.File class. Have a look there and see if there is a method you can use to do recursion.
i have done it for seaching a perticular file...
you can manipluate as per your need...
here is the code..
Joined: Mar 06, 2009
Vijay and Tsang,
thanks for your replies but
I dont have the luxury to search from an ABSOLUTE PATH i.e i cant search from C:\\ProgFiles\\
I am writing this code as a part of the service that is launched at the startup and returns to me the no. of tabs that the application is supposed to show.
it is supposed to go an scan the package "net.mm.ee.pages.tab1", "net.mm.ee.pages.tab2", and so on and so forth(all the pacakges that end with .tab(x)) but ignore "net.mm.ee.pages" ie(ignore the package that is without a tab suffix). I would be able to pass it the string "net.mm.ee.pages" only as a start point and not the directory paths.
Well I'm sure the search must start some where in the file structure. If its Unix root "/" or Windows root "C:/" or if possible get it as an input when instantiating the class in the constructor.
Joined: Jan 08, 2005
how you are getting the classpath & packages...
if you are reading it from System properties then
while looking at directories you can find out the expected package and do the job..
say for example you get c:\develpoments\project1; from the classpath then
while looking in this perticular directory you can calculate the what shold be the packages in the parent directory...
have you got what i meant to say
Joined: Mar 06, 2009
Apologies for a delayed reply..i was stuck with some of the other requirements...
well...a stupid question may be..
but could you let me know..how do find my packages through system properties.
I mean there is a whole lot of packages and Projects in my workspace..Now i want to check out what are the packages in my Workspace that match a specific pattern i.e i want to get all files in the package who belong to "net.mmm.pages" and its sub packages.
Could you let me know how can system properties help me..
Fist of all, I dont see the need for such traversing.
You seem to want to search for a file in your own project (if i am not wrong)
Here is what i would do if i was you.
1. Get the current path (easily done via the
2. Traverse Upwards to parent Folder (this is probably the Main Workspace folder eg: "MyWorkspace")
3. Now you are at the directory that is the parent for your application, you want to find a specific file in your workspace,
you can easily list out all project folder names, traverse to thier src directory and do the needful
if you want to be project specific, just traverse only to your project folder in step2