!--a11y-->
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 |
|
Copies
the resource. It requires the destination RID and an optional
|
|
Deletes the resource, collection or link. When the collection is deleted, all its children are also deleted. |
|
Moves the resource to another parent collection. It requires the same arguments as the copy() method. |
|
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/copyto /documents/folder/renamed.
● Deletes the renamed resource
IResourceContext context = new ResourceContext(user);
IResource resource = ResourceFactory.getInstance()
.getResource(″/documents/file″, context);
IResource copied = resource.copy(RID.getRID(″/documents/copy″), null);
IResource moved = copied.move(RID.getRID(″/documents/folder″), null);
IResource renamed = moved.rename(″renamed″);
renamed.delete();

When delete() is called, all the IResource objects in the example above are invalidated because they all reference the same resource. The resource only exists once. After the deletion of renamed, calling copied.delete() or moved.delete() throws a ResourceException.