[Tutor] Save file in a specific directory
Susana Iraiis Delgado Rodriguez
susana.delgado_s at utzmg.edu.mx
Tue Dec 7 18:20:12 CET 2010
My other message was incomplete, it was a mistake: This is the correct one
2010/12/7 Susana Iraiis Delgado Rodriguez <susana.delgado_s at utzmg.edu.mx>
> I make a script to redirect a txt file from an external directory, but in
> this directory I don't have permission to write, just to read data. So I
> make this module:
> import os, time,fnmatch
> from xlwt import Workbook
> from osgeo import ogr,gdal,osr
> from dbf import *
> gdal.AllRegister()
> file_list = []
> folders = None
> for root, folders, files in os.walk( "R:\\" ):
> for filename in fnmatch.filter(files, '*.shp'):
> file_list.append(os.path.join(root, filename))
> wrkbk = Workbook()
> wksht = wrkbk.add_sheet('shp')
> wksht.row(0).write(0,'ruta')
> wksht.row(0).write(1,'archivo')
> wksht.row(0).write(2,'estructura bd')
> 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)
> f = os.path.splitext(filename)
> t = f[0]+'_bd.txt'
> d = n[0]+'.dbf'
> if os.path.lexists(d):
> filepath = "C:\\Python26\\"
> a = open (filepath +t,"w+")
> dbf = Dbf(d,new=False)
> for fldName in dbf.fieldDefs:
> a.write(fldName.name)
> a.write(" || ")
> a.write(fldName.typeCode)
> a.write("\n")
> dbf.close()
> a.close()
> wksht.row(row).write(2, t)
> else:
> print "El archivo " +n[0]+".shp" " no tiene dbf"
> wksht.row(row).write(10, "Sin bd"
> wrkbk.save('C:\\Python26\\biblio_shp.xls')
>
When I run the script I got the next error:
>>> import crawler_shp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "crawler_shp.py", line 105, in <module>
dbf = Dbf(d,new=False)
File "C:\Python26\lib\site-packages\dbf.py", line 125, in __init__
self.stream = file(f, ("r+b", "rb")[bool(readOnly)])
IOError: [Errno 13] Permission denied: 'R:\\Aplicaciones\\IRISv3\\mis
proyectos\
\HURACAN\\BUFFER1000.dbf'
The error is pointing to a library I used to make the script run: dbf.py. in
thid lines:
if isinstance(f, basestring):
# a filename
self.name = f
if new:
# new table (table file must be
# created or opened and truncated)
self.stream = file(f, "w+b")
else:
# tabe file must exist
self.stream = file(f, ("r+b", "rb")[bool(readOnly)])
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101207/e37adaed/attachment-0001.html>
More information about the Tutor
mailing list