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
gdal.AllRegister()
#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
fi.endswith(".shp"))
#Open excel book
wrkbk = Workbook()
#Add excel sheet
wksht = wrkbk.add_sheet('shp')
wksht.row(0).write(0,'ruta')
wksht.row(0).write(1,'archivo')
wksht.row(0).write(2,'prj')
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)
 else:
      wksht.row(row).write(2, 0)
wrkbk.save('shp3.xls')
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to