Get files recursively inside directory in ruby

Question

Given the following directory structure:

$  tree .
.
└── some
    ├── Rakefile
    └── path
        ├── bar.erb
        └── to
            └── baz.rb

3 directories, 3 files

I'm able to get all files (including directories), only directories, and only files:

p Dir.glob('some/**/*')
#=> ["some/Rakefile", "some/path", "some/path/bar.erb", "some/path/to", "some/path/to/baz.rb"]
p Dir.glob('some/**/*/')
#=> ["some/path/", "some/path/to/"]
p Dir.glob('some/**/*').select { |f| File.file? f }
#=> ["some/Rakefile", "some/path/bar.erb", "some/path/to/baz.rb"]

Is there a more terse way to get only the files and not dirs (the third case)?

Edit:

Just to add an explicit answer to my question:
No. there isn't a shorter way, see this question


Show source
| ruby   2017-01-03 22:01 0 Answers

Answers to Get files recursively inside directory in ruby ( 0 )

Leave a reply to - Get files recursively inside directory in ruby

◀ Go back