code: def ensure_dir_exists(path):
      
  
      import os
  
      f_dir = os.path.dirname(path)
  
      if not os.path.exists(f_dir):
          os.makedirs(f_dir)
  
      return f_dir
docs: Given a file, ensure that the path to the file exists