POST
|
Thankyou so much for all your help, it worked perfectly and I have learnt so much. Really appreciate the help
... View more
07-27-2013
05:12 PM
|
0
|
0
|
601
|
POST
|
Not 100% certain but it appears it almost works, just you have a problem with the line return characters in retrieving the filename to copy from the text file: IOError: [Errno 22] invalid mode ('wb') or filename: 'C:\\\\Offences\\\\data\r\n' ...think you need to strip \r\n (which is line return\feed), easy enough to do, see the following test example entered interactively from IDLE - the print statement shows what you got on the return (which is 2 lines) and the 2nd print statement shows the corrected result (which is 1 line) after using strip:
>>> textfile = 'C:\\\\Offences\\\\data\r\n'
>>> print "'" + textfile + "'"
'C:\\Offences\\data
'
>>> textfile = textfile.strip()
>>> print "'" + textfile + "'"
'C:\\Offences\\data'
>>>
This is just an oft overlooked minor detail to take care of in reading text files. Enjoy, Wayne Thanks Wayne for your help...I am just learning and am still a little confused by what you have suggested and where I make the changes !! The idea of the script was to read the first file listed in the textfile = statement then open the text file called ArcReader_Servers.txt which consists of directory paths and copy the file to each of the locations. I only included the print statements as I was trying to see what was going wrong. I then want it to go to the 2nd file in the textfile = statement and repeat the process. Sorry for my lack of understanding but am still learning and appreciate the help. Thanks
... View more
07-27-2013
04:53 PM
|
0
|
0
|
601
|
POST
|
if this line textfile = (r'C:\Offences\state_jul.txt',r'C:\Offences\state_jun.txt') is supposed to be a list, then it must be enclosed in square brackets textfile = [r'C:\Offences\state_jul.txt',r'C:\Offences\state_jun.txt'] Tried that change but still get the same error ?
... View more
07-27-2013
05:30 AM
|
0
|
0
|
601
|
POST
|
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'
... View more
07-27-2013
12:28 AM
|
0
|
8
|
3611
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|