documentumdocumentum-dfcdocumentum-dql

How do I delete folders recursively using DQL?


I work on an application using Documentum. Let's say I have the following structure :

MyCabinetName
    |->Folder 1
        |->Folder 2
    |-> Folder 3

I am trying to delete all the folders inside a cabinet.

I am running the following DQL query :

delete dm_folder objects where folder ('MyCabinetName', DESCEND);

But when I run the query, I get a DQL ERROR :

[DM_FOLDER_E_CANT_DESTROY]error : "Cannot destroy folder with path name /MyCabinetName/Folder1 as it is not empty

I thought my query would delete recursively all folders inside MyCabinetName, but it does not seem to be the case, for if I run :

delete dm_folder objects where folder ('MyCabinetName/Folder1/Folder2', DESCEND);

and then

delete dm_folder objects where folder ('MyCabinetName/Folder1', DESCEND);

delete dm_folder objects where folder ('MyCabinetName/Folder3', DESCEND);

then

delete dm_folder objects where folder ('MyCabinetName', DESCEND);

will work.

Problem is that in real life, I don't know what my folder tree looks like. I just know the name of the cabinet whose content I want to delete.

Is there any way to delete a cabinet and its content recursively without having to delete each folder one by one?


Solution

  • It is not possible to delete folder with deep folder structure by DQL.

    But you can do it by Delete Operation, it means you can write a tool in Java, Groovy, ...

    Here is an example how to do that:

    IDfDeleteOperation operation = new DfClientX().getDeleteOperation();
    operation.setVersionDeletionPolicy(IDfDeleteOperation.ALL_VERSIONS);
    operation.setDeepFolders(true);
    operation.add("/MyCabinetName");
    if (!operation.execute()) {
        IDfList errors = operation.getErrors();
        // process errors
    }
    

    This line operation.setDeepFolders(true) instructs the operation to delete the folder with all sub-folders and other objects contained in the structure.