On 6/6/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Lou Losee wrote:
>
> > How about something like:
>
> > import os, stat
> >
> > class DirectoryWalker:
> > # a forward iterator that traverses a directory tree, and
> > # returns the filename
> > ...
>
> > not tested
>
> speak for yourse
Lou Losee wrote:
> How about something like:
> import os, stat
>
> class DirectoryWalker:
> # a forward iterator that traverses a directory tree, and
> # returns the filename
> ...
> not tested
speak for yourself ;-)
(the code is taken from http://effbot.org/librarybook/os-path.htm )
Here's the final working script. It opens all of the text files in a
directory and its subdirectories and combines them into one Rich text
file (index.rtf):
#! /usr/bin/python
import glob
import fileinput
import os
import string
import sys
index = open("index.rtf", 'w')
class DirectoryWalker:
Thanks everyone!
--
http://mail.python.org/mailman/listinfo/python-list
Thanks, that was a big help. It worked fine once I removed
> os.chdir("C:\\Python23\\programs\\Magazine\\SamplesE")
and changed "for file, st in DirectoryWalker("."):"
to
"for file in DirectoryWalker("."):" (removing the "st")
--
http://mail.python.org/mailman/listinfo/python-list
>>> Could someone tell me where to learn more about directory
>>> processes or show me an improved version of my first
>>> script snippet?
Use os.walk
http://docs.python.org/lib/os-file-dir.html
It takes a little reading to get it if you are a beginner, but there
are zillions of examples if you
>> there are far easier ways
>> #!/bin/bash
>> cat *.txt >outputfile
Well, yes, but if he's kicking things off with:
>> os.chdir("C:\\Python23\\programs\\filetree")
I'm guessing he's not on Linux. Maybe you're trying to convert him?
rd
--
http://mail.python.org/mailman/listinfo/python-list
On 2006-06-05, PipedreamerGrey <[EMAIL PROTECTED]> wrote:
Just in case you really are trying to accomplish something
other than learn Python, there are far easier ways to do these
tasks:
> This is the beginning of a script that I wrote to open all the
> text files in a single directory, then proc
On 5 Jun 2006 10:01:06 -0700, PipedreamerGrey <[EMAIL PROTECTED]> wrote:
> This is the beginning of a script that I wrote to open all the text
> files in a single directory, then process the data in the text files
> line by line into a single index file.
>
> os.chdir("C:\\Python23\\programs\\filetr
This is the beginning of a script that I wrote to open all the text
files in a single directory, then process the data in the text files
line by line into a single index file.
os.chdir("C:\\Python23\\programs\\filetree")
mydir = glob.glob("*.txt")
index = open("index.rtf", 'w')
for File in mydir
10 matches
Mail list logo