Copying, Moving and Deleting Resources

To copy, rename or delete a resource, you use the IResource interface. The methods available for these operations are shown in the table:

Method Purpose

copy()

Copies the resource. It requires the destination RID and an optional ICopyParameter as arguments. The parameter is a descriptor that can supply additional options for the copy operation, for example, to specify that children must be copied recursively.

delete()

Deletes the resource, collection or link. When the collection is deleted, all its children are also deleted.

move()

Moves the resource to another parent collection. It requires the same arguments as the copy() method.

rename()

Moves the resource to another parent collection. It requires the  same parameters as the copy() method.

The code extract below shows how to copy, move, rename and delete a resource. It:

  • Copies / documents/file to /documents/copy
  • Moves /documents/copy to /documents/folder/copy
  • Renames /documents/folder/copy to /documents/folder/renamed .
  • Deletes the renamed resource
IResourceContext context = new ResourceContext(user); 
IResource resource = ResourceFactory.getInstance()
.getResource(RID.getRID("/documents/file"), context); 
IResource copied = resource.copy(RID.getRID("/documents/copy"), null); 
IResource moved = copied.move(RID.getRID("/documents/folder"), null); 
String newName = "renamed"; 
moved.rename(newName); 
IResource renamed = ResourceFactory.getInstance()
  .getResource(RID.getRID("/documents" + newName), resourceContext); 
renamed.delete();