Hmm..... Use FindAllFiles (or something similar) to list all directories beneath your starting point, count files in each "end leaf" of that tree, if count=0 then NukeFolder
btw: When checking those "end leaves" of the tree, you have to start from the deepest level
example (result of FindAllFiles):
/home/zvoni/documents/folder1/folder2/folder3/folder4
/home/zvoni/documents/folder1/folder2/folder3
/home/zvoni/documents/folder1/folder2
etc.
Folder4 is empty --> delete it
Folder3 is NOW empty --> delete it
Folder2 NOW contains only a single txt-file --> Leave that whole Branch, since Folder1, documents, Zvoni, home won't be empty
etc.
EDIT: btw:
https://forum.lazarus.freepascal.org/index.php?topic=38849.0https://stackoverflow.com/questions/63592784/how-to-remove-empty-directory-recursively-in-delphi