Dealing with paths (Unix question)

P

paul

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.
 
T

Tyler Eaves

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?

Look at os.path.walk
 
A

Andy C

Or os.walk, that might be easier for a beginner. I think that's new though
in 2.3.
 
M

Michele Simionato

paul said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top