Hello Marc and Jim!
First of all, thanks to both of you!
I already changed the code, I added the try statement and the script runned
without ponting to an error. But now, I have another problem, even though,
it doesn't show an error message and makes the txt files, the files don't
have any lines written.
Before I added the try/catch lines, it showed the error, made the files and
writted them. I really need those txt files.
What did I do wrong?
import os,fnmatch
from osgeo import ogr,gdal,osr
from dbf import *
gdal.AllRegister()
file_list = []
folders = None
for root, folders, files in os.walk( "C:\\" ):
for filename in fnmatch.filter(files, '*.shp'):
file_list.append(os.path.join(root, filename))
for row, filepath in enumerate(file_list, start=1):
(ruta, filename) = os.path.split(filepath)
shapeData = ogr.Open(filepath)
if shapeData is None:
print 'Error al abrir el archivo' +filepath
else:
n = os.path.splitext(filepath)
f = os.path.splitext(filename)
b = f[0]+'_bd.txt'
d = n[0]+'.dbf'
if os.path.lexists(d):
filepath1 = "C:\\Python26\\dbf\\"
a = open (filepath1 +b,"w+")
try:
Dbf(d,new=False, readOnly=True)
for fldName in dbf.fieldDefs:
a.write(fldName.name)
a.write(" || ")
a.write(fldName.typeCode)
a.write("\n")
dbf.close()
a.close()
print n
except:
print 'El archivo ' +filepath+ ' esta vacio'
else:
print "El archivo " +n[0]+".shp" " no tiene dbf"
print "Listo"
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor