Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

copy text files to multiple directories using python

$
0
0
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'
Attached Files

Viewing all articles
Browse latest Browse all 2485

Trending Articles