[Tutor] SAVE FILE IN A SPECIFIC DIRECTORY

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Mon Dec 6 21:20:15 CET 2010


I'm trying to save files into a specific directory, the file will be
generated from a python script. The script will look for some data stored in
a directory which only allows to read files, it doesn't let the user write
or modify information. But when I run the script I got the next error:
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import crawler_shp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "crawler_shp.py", line 103, in <module>
    a = open (filepath +t,"w+")
IOError: [Errno 2] No such file or directory:
'C\\Python26\\BUFFER1000_bd.txt'
>>>
My script is:
import os, time, socket, pylab,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')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101206/72b3284d/attachment-0001.html>


More information about the Tutor mailing list