A directory in a filesystem may have no relationship between the number of entries inside and the "size" returned by stat. To find if a directory is empty, I would suggest one of:
Maybe:
- get the contents and see if it is empty (os.listdir, os.scandir, Path.iterdir)
- just call os.rmdir() on all of the directories, and ignore the errors. If its empty, it will be removed. If it's not empty, it won't.
Maybe:
if fel.is_dir(): if not any(fel.iterdir()): fel.rmdir()Or:
if fel.is_dir(): try: fel.rmdir() except OSError: pass