It's all about the answers!

Ask a question

Rename/Move a folder using java api


K M (38325251) | asked Nov 29 '10, 12:23 p.m.
How do you Rename/Move a folder with a workspace component
using the java api??

One answer



permanent link
K M (38325251) | answered Nov 30 '10, 8:52 a.m.
IVersionable filePath = (IVersionable) iconfig.fetchCompleteItem(filePathHandle, MONITOR);
if (!(filePath.hasFullState())) {
msg += "File " + fileNamePaths + " does not exists in component";
continue;
}

// Check if file or dir
if (filePath.getItemType() == IFileItem.ITEM_TYPE) {
// Get working copy
IFileItem file = (IFileItem) filePath.getFullState();
file = (IFileItem) file.getWorkingCopy();
file.setFileTimestamp(new Date());
file.setName(newName);

// Get delete operation
fileOps.add(workspace.configurationOpFactory().save(file));
msg += "Rename File " + fileNamePaths
+ " to " + newName + "\n";
} else {
IVersionable tmp_filePath = (IVersionable) filePath.getWorkingCopy();
tmp_filePath.setName(newName);

// Get delete operation
fileOps.add(workspace.configurationOpFactory().save(tmp_filePath));
msg += "Rename Dir " + fileNamePaths
+ " to " + newName + "\n";
}

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.