<div>Hello members:</div>
<div> </div>
<div>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.</div>
<div> </div>
<div>folders = None<br> # look in this (root) folder for files with specified extension<br>for root, folders, files in os.walk( "C:\\" ):<br> file_list.extend(os.path.join(root,fi) for fi in files if fi.endswith(".shp"))</div>
<div>wrkbk = Workbook()<br> #Add named parameter to allow overwriting cells: cell_overwrite_ok=True<br>wksht = wrkbk.add_sheet('shp') </div>
<div>#... add the headings to the columns</div>
<div>wksht.row(0).write(0,'ruta')<br>wksht.row(0).write(1,'archivo')</div>
<div>#write the rows</div>
<div>for row, filepath in enumerate(file_list, start=1): <br> wksht.row(row).write(0, filepath)<br> (ruta, filename) = os.path.split(filepath) <br> wksht.row(row).write(1, filename)</div>
<div> </div>
<div>#Here I`m splitting the string filename in base and extension</div>
<div>n = os.path.splitext(filename)</div>
<div>#Getting the base and prj as its extension<br> p = n[0]+'.prj'</div>
<div>#validate if p exists<br> if os.path.lexists(p):<br> wksht.row(row).write(9, 1) <br> prj_text = open(p, 'r').read()<br> wksht.row(row).write(8,prj_text)</div>
<div> else:<br> wksht.row(row).write(9, 0)<br> wksht.row(row).write(8, 'Sin prj, no se puede determinar la proyeccion')</div>
<div> </div>
<div>The issue is that it just identifies 3 prj and I have more, befores I added prj_text = open(p, 'r').read()<br> wksht.row(row).write(8,prj_text) it worked fine and write the correct prj, but now it doesn't</div>
<div> </div>
<div>What am I doing wrong? Hope you can help me</div>