SHARE
TWEET

Untitled

a guest Aug 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top