[Tutor] WRITING XLS FROM OS.WALK()

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Fri Oct 8 21:34:44 CEST 2010


Hello members:
I developed a Python module to make a list which contains all the files
ending with .shp and .dbf extensions, I have solved this already, but now I
want to write an excel file from it. The file should show the full path from
the found files. This is the code:

import os
a = open ("directorio.xls","w")
allfiles = [] #store all files found
     for root,dir,files in os.walk("C:\\"):
           filelist = [ os.path.join(root,fi) for fi in files if
fi.endswith(".shp") or fi.endswith(".dbf") ]
           for f in filelist:
                allfiles.append(f)
for i in allfiles:
      print i
      a.write(i)
      a.write("\n")

With the code above, I have the print and the .xls file with
this information in it, the issue here is that my file doesn't have the
complete information that I got in the console. Any idea? The last line from
excel is C:\Python26
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101008/b37698c3/attachment.html>


More information about the Tutor mailing list