Kent Johnson wrote:
> The Prophet wrote:
> > As my first Python script, I am trying to make a program that recurses
> > a directory searching for files whose names match a pattern.
>
> If your patterns are simple (supported by fnmatch), the path module
> makes this very easy:
> import path
> for f
The Prophet wrote:
> As my first Python script, I am trying to make a program that recurses
> a directory searching for files whose names match a pattern.
If your patterns are simple (supported by fnmatch), the path module
makes this very easy:
import path
for f in path.path(dirname).walkfiles('
> As my first Python script, I am trying to make a program that recurses
> a directory searching for files whose names match a pattern. I have a
> basic idea of what the regexp would look like
You probably don't need regexp for this, just use the fnmatch module
http://docs.python.org/lib/module-f
>> root, dirs, files = os.walk(dirname)
If you want to do it this way, you need to stop it after the first one:
root, dirs, files = os.walk(dirname).next()
print root
print dirs
print files
see this thread
http://tinyurl.com/rmyo4
--
http://mail.python.org/mailman/listinfo/python-list
Neat. And looks better, at least on my machine, if you had a tab or two
and an extra \n after the dirs.
rick
for filepath, dirs, files in os.walk(root):
#you're looking at the "dirs" and "files" in filepath
print "Currently in %s" % filepath
print "\t[Directories in %s]" %
> but I am stuck with incorrect understanding of
> os.walk. I've tried:
>
> root, dirs, files = os.walk(dirname)
os.walk returns an iteratable sequence of those tuples. Thus,
you want to have
for filepath, dirs, files in os.walk(dirname):
#you're looking at the "dirs" and "files" in fi