471,573 Members | 1,034 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,573 software developers and data experts.

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 1607
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 XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.