Rename/Move a folder using java api
One answer
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";
}
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";
}