[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to parse directory structure using ruby

Saurabh Purnaye

1/19/2008 8:06:00 AM

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

2 Answers

Tim Hunter

1/19/2008 8:49:00 AM

0

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.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

Robert Klemme

1/19/2008 10:45:00 AM

0

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