7
votes

How do I delete empty folders(folders without any content) by using Artifactory AQL?

I have the current AQL query to find files that are older than 12w and never downloaded, which I will delete by an script.

items.find(
    {
        "repo":{"$eq":"libs-release-local"},
        "stat.downloads":{"$eq":null},
        "created":{"$before" : "12w"},
    }
)

This leaves me with empty folders, how do I specify an AQL query that finds all empty folders?

2

2 Answers

4
votes

From Artifactory Query Language documentation: if type is not specified in the query, the default type searched for is file.

By adding a type to the query you can control the result type: file, folder or both.

For example:

items.find(
    {
        "repo": {"$eq":"libs-release-local"},
        "stat.downloads": {"$eq":null},
        "created": {"$before" : "12w"},
        "type": {"$eq":"any"}
    }
)
0
votes

If you are not married to the idea of using AQL, note that there is an Empty Folder Clean-up plugin by JFrog.