Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. # Check if a Directory is empty and also check exceptional situations.
  2.  
  3. import os
  4. path = "C:\\Users\\Hamed\\Desktop"
  5.  
  6. if os.path.exists(path) and os.path.isdir(path):
  7. if not os.listdir(path):
  8. print("Directory is empty")
  9. else:
  10. print("Directory is not empty")
  11. else:
  12. print("Given Directory don't exists")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement