My other message was incomplete, it was a mistake: This is the correct one<br><br>
<div class="gmail_quote">2010/12/7 Susana Iraiis Delgado Rodriguez <span dir="ltr"><<a href="mailto:susana.delgado_s@utzmg.edu.mx">susana.delgado_s@utzmg.edu.mx</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>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:</div>
<div>import os, time,fnmatch<br>from xlwt import Workbook<br>from osgeo import ogr,gdal,osr<br>from dbf import *</div>
<div>gdal.AllRegister()<br>file_list = []<br>folders = None<br>for root, folders, files in os.walk( "R:\\" ):<br>for filename in fnmatch.filter(files, '*.shp'):<br> file_list.append(os.path.join(root, filename))<br>
wrkbk = Workbook()<br> wksht = wrkbk.add_sheet('shp') <br> wksht.row(0).write(0,'ruta')<br> wksht.row(0).write(1,'archivo')<br> wksht.row(0).write(2,'estructura bd')<br> 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)<br> f = os.path.splitext(filename)<br> t = f[0]+'_bd.txt'<br>
d = n[0]+'.dbf'<br> if os.path.lexists(d):<br> filepath = "C:\\Python26\\"<br> a = open (filepath +t,"w+")<br> dbf = Dbf(d,new=False)<br>
for fldName in dbf.fieldDefs:<br> a.write(fldName.name)<br> a.write(" || ")<br> a.write(fldName.typeCode)<br> a.write("\n")<br> dbf.close()<br>
a.close()<br> wksht.row(row).write(2, t)<br> else:<br> print "El archivo " +n[0]+".shp" " no tiene dbf"<br> wksht.row(row).write(10, "Sin bd"<br>
wrkbk.save('C:\\Python26\\biblio_shp.xls')<br></div></blockquote>
<div>When I run the script I got the next error:</div>
<div>>>> import crawler_shp<br>Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br> File "crawler_shp.py", line 105, in <module><br> dbf = Dbf(d,new=False)<br>
File "C:\Python26\lib\site-packages\dbf.py", line 125, in __init__<br> self.stream = file(f, ("r+b", "rb")[bool(readOnly)])<br>IOError: [Errno 13] Permission denied: 'R:\\Aplicaciones\\IRISv3\\mis proyectos\<br>
\HURACAN\\BUFFER1000.dbf'</div>
<div> </div>
<div>The error is pointing to a library I used to make the script run: dbf.py. in thid lines:</div>
<div>if isinstance(f, basestring):<br> # a filename<br> <a href="http://self.name">self.name</a> = f<br> if new:<br> # new table (table file must be<br> # created or opened and truncated)<br>
self.stream = file(f, "w+b")<br> else:<br> # tabe file must exist<br> self.stream = file(f, ("r+b", "rb")[bool(readOnly)])</div>
<div> </div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div> </div></blockquote></div><br>