advance_touch_1.py 594 B

123456789101112131415161718
  1. def advance_touch(paths, cd):
  2. """ Make folders and files """
  3. for path in paths:
  4. # Make folders
  5. new_dirs = '/'.join(path.split('/')[0:-1])
  6. if not os.path.exists(new_dirs) and new_dirs != '':
  7. os.makedirs(new_dirs)
  8. # Change directory
  9. if cd:
  10. cd_path = os.path.join(os.getcwd(), new_dirs) + '/'
  11. os.chdir(cd_path)
  12. # Make file
  13. if not path.endswith('/') and not os.path.isfile(path):
  14. try:
  15. open(path, 'w+').close()
  16. except IsADirectoryError:
  17. pass