<div>Hello members:</div>
<div> </div>
<div>I&#39;m trying to validate the existence of a file by an if statement, but it isn&#39;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( &quot;C:\\&quot; ):<br>       file_list.extend(os.path.join(root,fi) for fi in files if fi.endswith(&quot;.shp&quot;))</div>

<div>wrkbk = Workbook()<br> #Add named parameter to allow overwriting cells: cell_overwrite_ok=True<br>wksht = wrkbk.add_sheet(&#39;shp&#39;) </div>
<div>#... add the headings to the columns</div>
<div>wksht.row(0).write(0,&#39;ruta&#39;)<br>wksht.row(0).write(1,&#39;archivo&#39;)</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]+&#39;.prj&#39;</div>
<div>#validate if p exists<br> if os.path.lexists(p):<br>  wksht.row(row).write(9, 1) <br>  prj_text = open(p, &#39;r&#39;).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, &#39;Sin prj, no se puede determinar la proyeccion&#39;)</div>
<div> </div>
<div>The issue is that it just identifies 3 prj and I have more, befores I added  prj_text = open(p, &#39;r&#39;).read()<br>  wksht.row(row).write(8,prj_text) it worked fine and write the correct prj, but now it doesn&#39;t</div>

<div> </div>
<div>What am I doing wrong? Hope you can help me</div>