spud007

copy text files to multiple directories using python

Discussion created by spud007 on Jul 27, 2013
Latest reply on Jul 28, 2013 by lpinner
I am trying to copy text files to various directories that are listed in a text file but keep getting errors, can anyone assist please ?

Python script below: and I have attached my text file


import os
import shutil
import string

textfile = (r'C:\Offences\state_jul.txt',r'C:\Offences\state_jun.txt')

with open(r'C:\ArcReader_Servers.txt', 'rb') as fp:
        for line in fp.readlines():
            filepath = line
            print filepath
            for i in textfile:
                filename = i
                print filename
                shutil.copy2(filename,filepath)

error I receive when I run is :

C:\\Offences\\data


C:\Offences\state_jul.txt
Traceback (most recent call last):
  File "C:\Offences\Distribution_Offences_ArcReader.py", line 14, in <module>
    shutil.copy2(filename,filepath)
  File "C:\Python26\ArcGIS10.0\lib\shutil.py", line 99, in copy2
    copyfile(src, dst)
  File "C:\Python26\ArcGIS10.0\lib\shutil.py", line 53, in copyfile
    fdst = open(dst, 'wb')
IOError: [Errno 22] invalid mode ('wb') or filename: 'C:\\\\Offences\\\\data\r\n'

Attachments

Outcomes