auto read multiple files

David LeBlanc whisper at oz.net
Thu May 9 11:37:20 EDT 2002


import os.path

(from 2.2.1 python doc):
walk(path, visit, arg)
Calls the function visit with arguments (arg, dirname, names) for each
directory in the directory tree rooted at path (including path itself, if it
is a directory). The argument dirname specifies the visited directory, the
argument names lists the files in the directory (gotten from
os.listdir(dirname)). The visit function may modify names to influence the
set of directories visited below dirname, e.g., to avoid visiting certain
parts of the tree. (The object referred to by names must be modified in
place, using del or slice assignment.)

python22/tools/versioncheck/checkversions.py has a usage example.

I just discovered this gem t'other day while perusing the doc.

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Rad
> Sent: Thursday, May 09, 2002 7:59
> To: python-list at python.org
> Subject: auto read multiple files
>
>
> Hi,
>
> I have about 2500 text files to read (and manipulate) from apx. 625
> directories (i.e. 4 files per directory) eg:
> C:\Python22\data\ProjectName\001\FileName1.001
> 				 FileName2.001
> 				 FileName3.001
> 				 FileName4.001
> C:\Python22\data\ProjectName\002\FileName1.002
> 				 FileName2.002
> 				 FileName3.002
> 				 FileName4.002
> 

> 

> C:\Python22\data\ProjectName\625\FileName1.625
> 				 FileName2.625
> 				 FileName3.625
> 				 FileName4.625
> I want to apply the same procedure/s to all(625) sets of four files
> without having to explicitly specify paths and FileNames, i.e. run the
> program and leave it over night to do the work on all 2500 files.
> I could create a list of all the file names and use it to access files
> 4 by 4 but I guess this is not the best way.
>
> Any ideas?
>
> P.S. If it makes things easier I could move all the files into one
> directory thus have fixed path. (related sets of 4 files have same
> extensions)
>
> P.P.S. Win98/Win2k
>        Python2.2.1
> --
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list