title: Python copy or move files whose names are on a list in a text file
body: <p>Can anyone tell me how to copy or move a batch of files to another directory or other directories. The name of the files are in a list that are in a text file. I'm working on a Windows system. The text file contains a list similar to this:</p>
  
  <pre><code>C:\dir1\dir3\dir4\file1.pdf
  C:\dir5\dir6\file2.txt
  c:\dir7\dir8\dir9\dir10\file3.pdf
  </code></pre>
  
  <p>...more file names</p>
  
  <p>I've tried readline() to read the file list and shutil.move(src, dest) to move the files, but don't know how to pass the src file properly, without getting an error.  Any suggestions on this way or another would be appreciated? Thanks.</p>
  
  <p>I tested using a file list that had just one entry:
  (filetest.txt):
  C:\Documents and Settings\Owner\My Documents\movetest.txt</p>
  
  <pre><code>import shutil
  
  # shutil.move(r'C:\Documents and Settings\Owner\My Documents\test4.txt', r'C:\Documents and Settings\Owner\My Documents\Test\test4.txt')
  
  filein = open('filetest.txt', 'r')
  line = filein.readline()
  name = 'r' + "'" + line[:len(line) - 1] + "'"
  shutil.move(name, 'movetest.txt')
  filein.close()`
  
  Traceback:
  
  Traceback (most recent call last):
    File "C:\Python33\Lib\shutil.py", line 522, in move
      os.rename(src, real_dst)
  OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'movetest.txt'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "C:/Documents and Settings/Owner/My Documents/Python 3 Programs/MoveTest10.py", line 12, in &lt;module&gt;
      shutil.move(name, 'movetest.txt')
    File "C:\Python33\Lib\shutil.py", line 534, in move
      copy2(src, real_dst)
    File "C:\Python33\Lib\shutil.py", line 243, in copy2
      copyfile(src, dst, follow_symlinks=follow_symlinks)
    File "C:\Python33\Lib\shutil.py", line 109, in copyfile
      with open(src, 'rb') as fsrc:
  OSError: [Errno 22] Invalid argument: "r'C:\\Documents and Settings\\Owner\\My Documents\\movetest.txt'"
  </code></pre>