Getting list of file handlers in an eclipse rcp project
I'm developing a RCP application. In a project workspace, I g开发者_运维百科et file/folder handlers of known files to me by getFile(String name)
and getFolder(String name)
methods.
Is there a method which returns array/list of files which matches a regex? (Like getFiles("*.txt")
).
EDIT: This works.
IResource members[] = aFolder.members();
for (int i = 0; i < members.length; i++) {
if (members[i].getName().endsWith(".java")) {
//Do something
}
}
If you know that the files/folders are all immediate children of the specified folder - aFolder
above - then you code is fine (see note below).
But if you want to access files at any level in the tree, then I would recommend to use the visitor construct: IResource.accept(IResourceProxyVisitor visitor, int memberFlags)
. There are a number of different versions of this, so you better check which match your needs best.
Note: One advantage of the IResourceProxyVisitor
over the other methods and over the explicit version that you have shown, is the fact that this version does not check the file system whether the resource still exists or not and therefore it is extremely fast.
精彩评论