7

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?

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
ki_
  • 619
  • 1
  • 10
  • 21

2 Answers2

4

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"}
    }
)
Roman G
  • 166
  • 5
  • 3
    This query finds folders which contains pom/artifacts as well. We are using Maven repos in Artifactory and Gradle as the tool to fetch and I guess that gradle never queries for the folders, just the pom and artifacts inside the folders. – ki_ Nov 28 '16 at 09:55
0

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