Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Avatar

Level 2

unnamed.png
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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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.