开发者

Getting list of file handlers in an eclipse rcp project

开发者 https://www.devze.com 2023-04-08 20:52 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号