Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: Python
Posted by: Jean-Pierre Hermans
Added: May 23, 2021 9:08 AM
Views: 364
Tags: no tags
  1. '''Check if directory exists, if not, create it'''
  2. import os
  3.  
  4. # You should change 'test' to your preferred folder
  5. MYDIR = ("test")
  6. CHECK_FOLDER = os.path.isdir(MYDIR)
  7.  
  8. #if it doesn't exist then create it
  9. if not CHECK_FOLDER:
  10.     os.makedirs(MYDIR)
  11.     print("created folder : ", MYDIR)
  12.  
  13. else:
  14.     print(MYDIR, "folder already exists.")
Comments disabled