import os

cesta=r"u:\d1"

folders=[]
for root,dirs,files in os.walk(cesta):
    for dir in dirs:
        folders.append(os.path.join(root,dir))


print(folders)

sorted_list = sorted(folders, key=len, reverse=True)
print(sorted_list)

for item in sorted_list:
    if len(os.listdir(item)) == 0:
        print(item)
        os.rmdir(item)
