Hi,
How to perform recursive file listening? Means that I want to list all
files in dir tree.
Thanks in advance
···
--
Posted via http://www.ruby-forum.com/.
Hi,
How to perform recursive file listening? Means that I want to list all
files in dir tree.
Thanks in advance
--
Posted via http://www.ruby-forum.com/.
On Mac OS X you can use FSEvents for this.
James Edward Gray II
On Sep 3, 2008, at 7:31 AM, Marcin Tyman wrote:
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
2008/9/3 Marcin Tyman <m.tyman@interia.pl>:
How to perform recursive file listening? Means that I want to list all
files in dir tree.
--
Aimred - Ruby Development and Consulting
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.
--
Posted via http://www.ruby-forum.com/.
Farrel Lifson wrote:
2008/9/3 Marcin Tyman <m.tyman@interia.pl>:
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 ![]()
--
Posted via http://www.ruby-forum.com/\.
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.
On Wed, Sep 7, 2011 at 2:43 PM, Andrius C. <andrius.chamentauskas@gmail.com>wrote:
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/fileIt will return only "file" and "first_level/file", but will not return
"first_level/second_level/file".
Did you actually test this? I did, and here is what I got:
jeremyb@JEREMYB ~/tmp/test
$ mkdir -p first_level/second_level
jeremyb@JEREMYB ~/tmp/test
$ touch file.rb first_level/file.rb first_level/second_level/file.rb
jeremyb@JEREMYB ~/tmp/test
$ find .
.
./file.rb
./first_level
./first_level/file.rb
./first_level/second_level
./first_level/second_level/file.rb
jeremyb@JEREMYB ~/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 9/7/2011 08:43, Andrius C. wrote:
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/fileIt will return only "file" and "first_level/file", but will not return
"first_level/second_level/file".
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.
--
Posted via http://www.ruby-forum.com/\.
Clearly I don't use globs enough. ![]()
On Wed, Sep 7, 2011 at 3:21 PM, Jeremy Bopp <jeremy@bopp.net> wrote:
Did you actually test this? I did, and here is what I got:
[snip]