[Tutor] If os.path.lexists() isn't working properly

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Wed Nov 24 17:19:46 CET 2010

Hello memebers:

I'm writing a python script to validate if files with extension .prj exist,
if they exist it should write 1 or 0 into an excel cell. I've working to do
this properly, but I'm not getting the results I need. The script doesn't
find all the files, is like the files don't exist but they exist, besides I
think is just reading some of the files that are in C:\Python 26. I really
need a hand on this.

import os, time, socket, pylab
from xlwt import Workbook
from osgeo import ogr,gdal,osr
from dbf import *
#Register GAL drivers
#Create an empty list
file_list = []
folders = None
#Code to indicate directory
for root, folders, files in os.walk( "C:\\" ):
 file_list.extend(os.path.join(root,fi) for fi in files if
#Open excel book
wrkbk = Workbook()
#Add excel sheet
wksht = wrkbk.add_sheet('shp')
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)
 n = os.path.splitext(filename)
 p = n[0]+'.prj'
 if os.path.lexists(p):
      wksht.row(row).write(2, 1)
      wksht.row(row).write(2, 0)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101124/b6f3d660/attachment.html>

More information about the Tutor mailing list