0

Trying to copy via a python script 4 text files to multiple directories that are shown in a text file ? I'm just learning python so help would be appreciated, listed below is what I have done so far but it doesn't work

import os
import shutil
import string

txtfile = [r"S:\Offences\state_jul.txt","S:\Offences\state_jun.txt","S:\Offences\state_apr.txt"]
f = open(r"D:\Scripts\Python\ArcReader_Servers.txt","r")

if f:
    filepath = f.readline()
    while filepath:
        for i in range(len(txtfile)):
            filename = txtfile[i]
            print filename
            shutil.copy2(filename,filepath)
        filepath = f.readline()
        print filepath
icktoofay
  • 126,289
  • 21
  • 250
  • 231
Deb
  • 1
  • 3
  • Can you be more specific about what you mean by “doesn't work”? Are you getting an error, is it not doing *anything*, or is it doing something, but just something that you didn't expect? – icktoofay Jul 27 '13 at 03:28
  • sorry it is coming up with IOError: [Errno 22] invalid mode ('wb') or filename: – Deb Jul 27 '13 at 03:37
  • Why do you have those `r`'s before the first value in `textfile` and `open`? Also, to iterate over textfile, why not just `for i in textfile:`? – Houdini Jul 27 '13 at 03:37
  • thought you had to have the r as it was a string ??? I'm just learning – Deb Jul 27 '13 at 03:39
  • 1
    String literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and use different rules for interpreting backslash escape sequences. [Python Documentation](http://docs.python.org/2/reference/lexical_analysis.html#string-literals) That means that without it (the prefix) each backslash has to be doubled up if you don't want them to be interpreted as the start of an escape sequence. [more info](http://stackoverflow.com/questions/2081640/what-exactly-do-u-and-rstring-flags-in-python-and-what-are-raw-string-litte?answertab=votes#tab-top) – ecr Jul 27 '13 at 03:51
  • I dont think this should be tagged `python-3.x`, its looks like 2 to me. – Houdini Jul 27 '13 at 04:34

0 Answers0