title: Python 3.6: Looping through files in os.listdir() and writing some of them to a text document
body: <p>I'm trying to loop through some files and write the file names of the .txt ones to another .txt </p>
  
  <p>the piece of code stops after finding and writing the name of one file. </p>
  
  <p>how would I get it to write the names of the rest? </p>
  
  <pre><code>import os
  
  os.chdir('/users/user/desktop/directory/sub_directory')
  
  for f in os.listdir():
      file_name, file_ext = os.path.splitext(f)
      if file_ext == '.txt':
          with open('file_test.txt', 'r+') as ft:
              ft.write(file_name)
  </code></pre>