title: Accessing a Directory and Creating and Writing to a File in Python
body: <p>I need to write a program that</p>
  <ol>
  <li>prompts the user to input a valid directory path</li>
  <li>tells the user the directory is valid or invalid,</li>
  <li>creates a file</li>
  <li>writes a name, address and phone number to that file and</li>
  <li>displays to the user the name, address and phone number written to the file.</li>
  </ol>
  <p>I looked here and other sources and learned how to utilize tKinter, where a pop-up window allows the user to select the directory and file before writing to that file...but I need the program to prompt the user for the directory path and have it validated: That's where I'm stuck...</p>
  <p>Thanks! Here is my code thus far:</p>
  <pre><code>print('Please choose a .txt file from the pop-up window')
  
  from tkinter import Tk
  from tkinter.filedialog import askopenfilename
  
  Tk().withdraw()
  filename = askopenfilename()
  print(filename)
  
  print('Now, please enter the .txt file name exactly as shown at the end of the directory path above: ')
  file_name = input()
  
  print('Now, please input your name: ')
  name = input()
  print('Next, enter your address: ')
  address = input()
  print('Finally, please enter your phone number: ')
  phone = input()
  
  
  file = open(file_name, 'w')
  file.write(name + &quot;, &quot;)
  file.write(address + &quot;, &quot;)
  file.write(phone)
  file.close()
  
  file = open(file_name, 'r')
  file_contents = file.read()
  print('You input the following information into your chosen .txt file: ', file_contents)
  print('Good-bye')
  </code></pre>