It's all about the answers!

Ask a question

Finding a file in a component using java api


K M (38325251) | asked Aug 05 '10, 8:08 a.m.
I can find a file that is at the root folder using the folliwng methods

IConfiguration iconfig = (IConfiguration) workspace.configuration(component);
IFolderHandle root = iconfig.rootFolderHandle(MONITOR);
IVersionableHandle filePathHandle = iconfig.resolvePath(root,fileName, MONITOR);

How do I find the file if it is not at the root folder level??

One answer



permanent link
K M (38325251) | answered Aug 05 '10, 10:14 a.m.
there should be a simpler way.......


public IVersionableHandle findfile(IFolderHandle root,IConfiguration iconfig,String fileName)
throws TeamRepositoryException {
String fileNamePath[] = {fileName};
IVersionableHandle filePathHandle = null;

// Check if file at this folder level
filePathHandle = iconfig.resolvePath(root,fileNamePath, MONITOR);
if (filePathHandle != null) {
return filePathHandle;
}

// Check this file sub folders
Map<String> childEntries = iconfig.childEntries(root,MONITOR);
for(Map.Entry<String> next : childEntries.entrySet()) {
IVersionableHandle nextVersionable = next.getValue();
if (nextVersionable instanceof IFolderHandle) {
filePathHandle = findfile((IFolderHandle) nextVersionable,iconfig,fileName);

if (filePathHandle != null) {
break;
}
}
}
return filePathHandle;
}

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.