title: mkdir error file path does not exist in python
body: <p>please guys am a beginner in python and was trying to create a simple to-do-list program, but am stuck right now at the point of making directory. I will be posting the code below all suggest to help and make it better is welcome.</p>
  <pre><code>#!/usr/bin/env python3
  
  def_directory = &quot;~/Documents/&quot;
  
  def fi_le():
      x = int(input(&quot;Enter The Length of Your To-Do-List: &quot;))
  
  #this next line of codes should generate the number of list you want
  xf = list(range(1, (x + 1)))
  
  #This next liine asks for the To-do list name
  import os.path
  directory = def_directory
  namer = input(&quot;Enter File Name: &quot;)
  file_name = namer + &quot;.txt&quot;
  file_path = os.path.join(directory, file_name)
  
  if not os.path.isdir(directory):
      os.mkdir(directory)
  
  f = open(file_path, &quot;w+&quot;)
  
  #This next line of code takes in user To-Do-List
  for i in xf:
      l = (&quot;=&gt;&quot; + str(i) + &quot;. &quot;)
  
  f.close()
  
  def dir_check():
      print(&quot;\n&quot;)
      print(&quot;*NOTE: PLEASE NOTE YOUR DEFAULT DIR FOR SAVED FILE IS THE 'DOCUMENTS FOLDER'&quot;)
      print(&quot;IF YOU WANT TO CHANGE DIR ENTER 'C' TO PROCEED ELSE ENTER 'D' TO USE DEFAULT FOLDER&quot;)
      print(&quot;\n&quot;)
  
  ask_user = input(&quot;Do you want to Proceed with DEFAULT FOLDER: &quot;).upper()
  
  if ask_user == &quot;D&quot;:
      fi_le()
  
  elif ask_user == &quot;C&quot;:
      user_folder_name = (&quot;~/&quot; + input(&quot;Specify Folder Name: &quot;))
      def_directory = user_folder_name
      fi_le()
  
  else:
      print(&quot;Please Enter 'D' Or 'C' to Continue&quot;)
      dir_check()
  
  dir_check()
  
  
  
  print(&quot;\n&quot; * 5)
  print(&quot;===============&gt; End &lt;===============&quot;)
  </code></pre>