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', 'r') as fp: for filepath in fp.readlines(): filepath=filepath.strip() #Strip off the print filepath for filename in textfile: print filename shutil.copy2(filename,filepath)
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' ...think you need to strip (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' >>> 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
>>> textfile = 'C:\\\\Offences\\\\data' >>> print "'" + textfile + "'" 'C:\\Offences\\data ' >>> textfile = textfile.strip() >>> print "'" + textfile + "'" 'C:\\Offences\\data' >>>
if this linetextfile = (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 bracketstextfile = [r'C:\Offences\state_jul.txt',r'C:\Offences\state_jun.txt']
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.