how to parse directory structure using ruby

Discussion in 'Ruby' started by Saurabh Purnaye, Jan 19, 2008.

  1. Hi all,
    Greetings..
    In my project i have stuck a place .. where i have to parse directory
    structure.
    Can you please help me out in this ?
    The requirement is like... i will give input as name of directory..
    The program should act like to parse the whole directory structure and
    give me output as, with all the directories/files with the name...
    --
    Posted via http://www.ruby-forum.com/.
     
    Saurabh Purnaye, Jan 19, 2008
    #1
    1. Advertising

  2. Saurabh Purnaye

    Tim Hunter Guest

    Saurabh Purnaye wrote:
    > Hi all,
    > Greetings..
    > In my project i have stuck a place .. where i have to parse directory
    > structure.
    > Can you please help me out in this ?
    > The requirement is like... i will give input as name of directory..
    > The program should act like to parse the whole directory structure and
    > give me output as, with all the directories/files with the name...


    Check out the "find" extension in the standard library.

    ri Find#find
    -------------------------------------------------------------- Find#find
    find(*paths) {|path| ...}
    ------------------------------------------------------------------------
    Calls the associated block with the name of every file and
    directory listed as arguments, then recursively on their
    subdirectories, and so on.

    See the Find module documentation for an example.



    --
    RMagick: http://rmagick.rubyforge.org/
    RMagick 2: http://rmagick.rubyforge.org/rmagick2.html
     
    Tim Hunter, Jan 19, 2008
    #2
    1. Advertising

  3. On 19.01.2008 09:49, Tim Hunter wrote:
    > Saurabh Purnaye wrote:
    >> Hi all,
    >> Greetings..
    >> In my project i have stuck a place .. where i have to parse directory
    >> structure.
    >> Can you please help me out in this ?
    >> The requirement is like... i will give input as name of directory..
    >> The program should act like to parse the whole directory structure and
    >> give me output as, with all the directories/files with the name...

    >
    > Check out the "find" extension in the standard library.
    >
    > ri Find#find
    > -------------------------------------------------------------- Find#find
    > find(*paths) {|path| ...}
    > ------------------------------------------------------------------------
    > Calls the associated block with the name of every file and
    > directory listed as arguments, then recursively on their
    > subdirectories, and so on.
    >
    > See the Find module documentation for an example.


    And then there is of course Dir[] as well. For simple outputting it's
    probably easier:

    ruby -e 'puts Dir["**/*"]'

    Btw, the process is not called "parsing". In this case I'd rather use
    the term "traversing". "Parsing" usually means read a byte sequence and
    determine its structure according to some grammar.

    Kind regards

    robert
     
    Robert Klemme, Jan 19, 2008
    #3
    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. john
    Replies:
    4
    Views:
    678
    Jim Higson
    Jun 15, 2006
  2. Replies:
    19
    Views:
    1,137
    Daniel Vallstrom
    Mar 15, 2005
  3. Viegas
    Replies:
    1
    Views:
    364
    travishein
    Aug 22, 2008
  4. 7stud --

    optparse: parse v. parse! ??

    7stud --, Feb 20, 2008, in forum: Ruby
    Replies:
    3
    Views:
    190
    7stud --
    Feb 20, 2008
  5. lg
    Replies:
    3
    Views:
    303
    Tad McClellan
    Aug 9, 2007
Loading...

Share This Page