Dealing with paths (Unix question)

Discussion in 'Python' started by paul, Aug 3, 2003.

  1. paul

    paul Guest

    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.
     
    paul, Aug 3, 2003
    #1
    1. Advertising

  2. paul

    Tyler Eaves Guest

    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.
     
    Tyler Eaves, Aug 3, 2003
    #2
    1. Advertising

  3. paul

    Andy C Guest

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

    "Tyler Eaves" <> wrote in message
    news:p...
    > 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.
    >
     
    Andy C, Aug 3, 2003
    #3
  4. paul

    paul Guest

    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.
     
    paul, Aug 3, 2003
    #4
  5. paul <appleseed-cast~NOSPAM~@breathe.com> wrote in message news:<>...
    > 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.
     
    Michele Simionato, Aug 3, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    476
    Patrick May
    Nov 19, 2005
  2. Replies:
    12
    Views:
    1,673
    Dave Thompson
    Jan 10, 2005
  3. Noah
    Replies:
    5
    Views:
    818
  4. Anonymous
    Replies:
    0
    Views:
    201
    Anonymous
    Apr 3, 2008
  5. Ohad Lutzky

    Paths, gentleman, paths

    Ohad Lutzky, Nov 6, 2006, in forum: Ruby
    Replies:
    2
    Views:
    210
    David Vallner
    Nov 7, 2006
Loading...

Share This Page