cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

Get WTLibrary subfolder

VasiliyRepecki
1-Newbie

Get WTLibrary subfolder

Hi.

How can i get all subfolders for given WTLibrary or get subfolder by its name by java code?

I can not see any useful methods at FolderHelper. Should i use QuerySpec for my problem?

Thanks.

4 REPLIES 4

Going from memory here, but I think you need to start with the Cabinet when trying to get a Folder/SubFolder by name. The cabinet name is most likely "DEFAULT" (I think), so you could go about it a number of ways, depending on what exactly you want to do.

WTLibrary library = .....

WTContainerRef cr;

Folder f;

Cabinet c;

QueryResult qr;

SubFolder sf;

cr = WTContainerRef.newWTContainerRef(library);

f = FolderHelper.service.getFolder("/DEFAULT/FolderA/Folder1");

c = FolderHelper.service.getFolder("/DEFAULT");

qr = FolderHelper.service.findSubFolders((Folder)c);

while(qr.hasMoreElements()) {

sf = (SubFolder)qr.nextElement();

}

Or maybe if you want all folders inside the container at once? This may work, though I'm not really sure.

QuerySpec qs = new QuerySpec(SubFolder.class);

qs.appendWhere(new SearchCondition(SubFolder.class,SubFolder.CONTAINER_REF + ".key",SearchCondition.EQUAL,PersistenceHelper.getObjectIdentifier(library)),new int[]{0});

//WTAttributeNameIfc has something that should probably be referenced for ".key" and ".id" stuff instead of always hardcoding them.

qr = PersistenceHelper.manager.find(qs);

I have wt.folder.FolderNotFoundException for "/DEFAULT"

Try "/Default"

If that's no good, try the QuerySpec option and debug. There may also be a preference to show cabinets in the UI?

Matthew Knight, thanks a lot.

Default works!

Top Tags