title: How to use the file path as the source parameter from os.walk to copy files
body: <p>Okay, so I'm not sure how to get python to use the path to a file that it found through an os.walk function as the <code>source</code> parameter for the <code>shutil.copy(source, destination)</code> arguments.</p>
  <p>My code example is this</p>
  <pre><code>for folderName, subfolders, filenames in os.walk('/Users/me/Documents'):
      print('The current folder is '+folderName)
      for subfolder in subfolders:
          print('SUBFOLDER OF '+folderName+&quot;: &quot;+subfolder)
      for filename in filenames:
          print(&quot;FILE INSIDE &quot;+folderName+&quot;: &quot;+filename)
          if filename.endswith('.txt'):
              os.chdir(filename)
              shutil.copy(filename, '/Users/me/Documents/School/IT 145/Text Files')
      print(&quot;&quot;)
  </code></pre>
  <p>If the file has a .txt extension, I would like python to copy that file to the specified folder.</p>
  <p>My error message I get is this</p>
  <pre><code>The current folder is /Users/me/Documents/Text Files
  FILE INSIDE /Users/me/Documents/Text Files: guest.txt
  Traceback (most recent call last):
    File &quot;/Users/me/Documents/School/IT 145/Programming Work/os_walk.py&quot;, line 16, in &lt;module&gt;
      os.chdir(filename)
  FileNotFoundError: [Errno 2] No such file or directory: 'guest.txt'
  </code></pre>
  <p>From what I understand, python is going back to the current working directory to do the shutil.copy, but I don't understand why if I pass it the file path that it just found it won't use that as the source path for the file to copy.</p>
  <p>This is my first ever python programming class, and really my first brush with python all, so any teaching thoughts would be greatly appreciated. Thank you very much.</p>