Hello members:
I'm trying to validate the existence of a file by an if statement, but it
isn't working correctly. The module is a crawler that writes to excel some
attributes from the files it finds.
folders = None
# look in this (root) folder for files with specified extension
for root, folders, files in os.walk( "C:\\" ):
file_list.extend(os.path.join(root,fi) for fi in files if
fi.endswith(".shp"))
wrkbk = Workbook()
#Add named parameter to allow overwriting cells: cell_overwrite_ok=True
wksht = wrkbk.add_sheet('shp')
#... add the headings to the columns
wksht.row(0).write(0,'ruta')
wksht.row(0).write(1,'archivo')
#write the rows
for row, filepath in enumerate(file_list, start=1):
wksht.row(row).write(0, filepath)
(ruta, filename) = os.path.split(filepath)
wksht.row(row).write(1, filename)
#Here I`m splitting the string filename in base and extension
n = os.path.splitext(filename)
#Getting the base and prj as its extension
p = n[0]+'.prj'
#validate if p exists
if os.path.lexists(p):
wksht.row(row).write(9, 1)
prj_text = open(p, 'r').read()
wksht.row(row).write(8,prj_text)
else:
wksht.row(row).write(9, 0)
wksht.row(row).write(8, 'Sin prj, no se puede determinar la proyeccion')
The issue is that it just identifies 3 prj and I have more, befores I
added prj_text = open(p, 'r').read()
wksht.row(row).write(8,prj_text) it worked fine and write the correct prj,
but now it doesn't
What am I doing wrong? Hope you can help me
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor