how to parse directory structure using ruby

S

Saurabh Purnaye

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...
 
T

Tim Hunter

Saurabh said:
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.
 
R

Robert Klemme

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top