The task is to delete empty folders. The code below only deletes the last folder and turns off. But, after deleting the last folder, the folder in which it was located also becomes empty. How to make the script after deleting the last folder check the folder from which it deleted the last one and deleted it?
def del_empty_dirs(path): for d in os.listdir(path): a = os.path.join(path, d) if os.path.isdir(a): if not os.listdir(a): os.rmdir(a) print(a, 'удалена') else: del_empty_dirs(a)