469,290 Members | 1,922 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

Dealing with paths (Unix question)

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.
Jul 18 '05 #1
4 1561
On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote:
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
--
Visit my blog - http://blog.scalegen.com
Music, Programming, and More.

Jul 18 '05 #2
Or os.walk, that might be easier for a beginner. I think that's new though
in 2.3.

"Tyler Eaves" <ty***@scalegen.com> wrote in message
news:pa****************************@scalegen.com.. .
On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote:
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
--
Visit my blog - http://blog.scalegen.com
Music, Programming, and More.

Jul 18 '05 #3
On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote:
hey there all!

<snip>

cheers for the replies Tyler, Bjorn and Andy. I'll be checking out
os.path, etc...

fun fun fun...
paul.

Jul 18 '05 #4
paul <ap********************@breathe.com> wrote in message news:<pa***************************@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/Coo.../Recipe/212959

M.S.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Shane Thomas | last post: by
3 posts views Thread by Jeff | last post: by
6 posts views Thread by Jon Slaughter | last post: by
5 posts views Thread by antar2 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.