How to parse directory structure using ruby

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…

Saurabh P. 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.

On 19.01.2008 09:49, Tim H. wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs