Robert Klemme
1/19/2008 10:45:00 AM
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