Hi,
How to perform recursive file listening? Means that I want to list all
files in dir tree.
Thanks in advance
Hi,
How to perform recursive file listening? Means that I want to list all
files in dir tree.
Thanks in advance
On Sep 3, 2008, at 7:31 AM, Marcin T. wrote:
How to perform recursive file listening? Means that I want to list all
files in dir tree.
On Mac OS X you can use FSEvents for this.
James Edward G. II
2008/9/3 Marcin T. [email protected]:
How to perform recursive file listening? Means that I want to list all
files in dir tree.
Dir.glob(’**/*.rb’)
will return an array with all filenames ending with .rb reursively.
Farrel
Farrel L. wrote:
2008/9/3 Marcin T. [email protected]:
How to perform recursive file listening? Means that I want to list all
files in dir tree.Dir.glob(’**/*.rb’)
will return an array with all filenames ending with .rb reursively.
Farrel
Thanks you were helpful
On Wed, Sep 7, 2011 at 2:43 PM, Andrius C.
[email protected]wrote:
“first_level/second_level/file”.
You can also give Dir["//*.rb"] a try. It’ll give files in the
current
directory and deeper, even though the presence of two "/"s might mislead
you
to think otherwise.
Sorry for bumping old thread, but as it was first result for me in
google I’d like to add that Dir.glob(’**/*.rb’) won’t actually list
files recursively. It will only list files in current directory and 1
directory deep. So if you have files:
file
first_level/file
first_level/second_level/file
It will return only “file” and “first_level/file”, but will not return
“first_level/second_level/file”. To actually list files recursively you
can use little known “find” lib from stdlib:
http://ruby-doc.org/stdlib/libdoc/find/rdoc/classes/Find.html.
On 9/7/2011 08:43, Andrius C. wrote:
“first_level/second_level/file”.
Did you actually test this? I did, and here is what I got:
[email protected] ~/tmp/test
$ mkdir -p first_level/second_level
[email protected] ~/tmp/test
$ touch file.rb first_level/file.rb first_level/second_level/file.rb
[email protected] ~/tmp/test
$ find .
.
./file.rb
./first_level
./first_level/file.rb
./first_level/second_level
./first_level/second_level/file.rb
[email protected] ~/tmp/test
$ ruby -e ‘puts Dir.glob("**/*.rb").join("\n")’
file.rb
first_level/file.rb
first_level/second_level/file.rb
The meaning of ** in the glob means to match any and all intervening
directories at that point in the pattern. Can you explain why you think
that is not the case?
-Jeremy
On Wed, Sep 7, 2011 at 3:21 PM, Jeremy B. [email protected] wrote:
Did you actually test this? I did, and here is what I got:
[snip]
Clearly I don’t use globs enough.
Andrius C. wrote in post #1020607:
Sorry for bumping old thread, but as it was first result for me in
google I’d like to add that Dir.glob(’**/*.rb’) won’t actually list
files recursively. It will only list files in current directory and 1
directory deep.
You are wrong.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs