Groovy Script for getting count of folders with specific name and deleting their content | Community
Skip to main content
Level 2
May 6, 2022 6:03 AM UTC
Solved

Groovy Script for getting count of folders with specific name and deleting their content


As highlighted in the image , I need to write a Groovy Script to get a count of all the folder with the name "renditions" and as a secondary task, I need to delete content from all the such folders.

Any help would be greatly appreciated,
Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
May 6, 2022 8:23 AM UTC

Hi,

You can do something like below


path = "/content/dam/myproj"
renditionsNodeName = "renditions"
renditionsPath = "/renditions/"
NT_FILE = "nt:file"

renditionsNodeFound = 0


getNode(path).recurse { node ->
if(node.name == renditionsNodeName){
renditionsNodeFound++;
}
else if (node.path.contains(renditionsPath) && node.getPrimaryNodeType()==NT_FILE) {
node.remove();
}
}

println "\n ${renditionsNodeName} count = ${renditionsNodeFound}"
save()

 Note: This is not tested and could have compilation or logic issues.

Arun Patidar

1 reply

arunpatidar
arunpatidarAccepted solution
New Participant
May 6, 2022 8:23 AM UTC

Hi,

You can do something like below


path = "/content/dam/myproj"
renditionsNodeName = "renditions"
renditionsPath = "/renditions/"
NT_FILE = "nt:file"

renditionsNodeFound = 0


getNode(path).recurse { node ->
if(node.name == renditionsNodeName){
renditionsNodeFound++;
}
else if (node.path.contains(renditionsPath) && node.getPrimaryNodeType()==NT_FILE) {
node.remove();
}
}

println "\n ${renditionsNodeName} count = ${renditionsNodeFound}"
save()

 Note: This is not tested and could have compilation or logic issues.

Translate
Arun Patidar