Reputation: 1
I have an exercise to walk through all direcories in a subdirectory and check if there are empty or not. I already tried something but this don't work:
import os
path = input(">>> ")
for (root,dirs,files) in os.walk(path, topdown=True):
if len(dirs and files) == 0:
print(os.listdir(dirs)) == 0
print(root)
print(dirs)
print(files)
print('--------------------------------')
else:
print()
Can you help me with it?
Thanks
Upvotes: 0
Views: 476
Reputation: 26
You can try this:
'''
Check if a Directory is empty :
'''
if len(os.listdir(path) ) == 0:
print("Directory is empty")
else:
print("Directory is not empty")
Upvotes: 1