Dealing with paths (Unix question)

Michele Simionato mis6 at pitt.edu
Sun Aug 3 16:45:44 EDT 2003


paul <appleseed-cast~NOSPAM~@breathe.com> wrote in message news:<pan.2003.08.03.03.04.38.88618 at breathe.com>...
> hey there all!
> i'm writing some little programs, and i'd like to know about how to deal
> with directories on unix.  i've read up on this, but the docs don't really
> mention much on it.  do i use the pickle module, or something?
> 
> what i'd like to do is read in a path, say
> /home/username/images/
> and that path contains a dir called downloads and some png files, 
> and it also contains another dir called icons, which holds jpg, png and
> gif files.
> Now, is it posible to go through that top directory and recursively go
> through /icons/ and /downloads/ and pick out all files of a certain
> extension(only png files, for example)?
> 
> something like:
> for each_file in /home/username/images:
> 	if image_extension is png:
> 		add image path to list
> but as i said, i need something to work recursively though an arbitrary
> number of directories.
> 
> sorry if i wan't too clear here :/
> if anyone can post some clues on the modules/methods i'd use, and maybe
> some example code, that'll be *very* much appreciated!
> 
> thanks for reading.
> paul.

You may also want to look at this recipe:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/212959

         M.S.




More information about the Python-list mailing list