Advertisement
eeperry

Create File/Folder in Home Directory If Does Not Exist

Oct 5th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.19 KB | None | 0 0
  1. import os
  2.  
  3. path = os.path.join(os.getenv('HOME'), 'dirname')
  4. filename = os.path.join(path, 'file')
  5.  
  6. if not os.path.exists(path):
  7.     os.mkdir(path)
  8.  
  9. # do what is needed to create the file in path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement