How to search for and display files in a bunchof subdirectory??

Steve Purcell stephen_purcell at yahoo.com
Tue Apr 17 07:01:35 EDT 2001


Tsang, Edward1 wrote:
> Let say I invoke the script in directory d, but I have abunch of
> subdirectories under d.
> 
> tpTcCTFTEST10/         tpTcCTFTESTTIGHT02/    tpTcTNLC14_2/
> tpTcTNLC6_5/
> 
> and each subdirectory contains a file tp_acc.1. I want to do some processing
> to this file, but asking the user to click each folder and input the file
> name is just too much work for them, how can I just display the files in the
> subdirectories. 


Use the 'glob' module, which simulates '*' and '?' expansion of filenames:

   import glob
   filenames = glob.glob('tpTc*/tp_acc.1')

'filenames' will now contain a list of the files in the subdirectories.

-Steve

-- 
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo




More information about the Python-list mailing list