Search code examples
rubyglob

Dir globbing not recursing fully


files = Dir[File.join(path, '**', '*.jpg')].each do |s| 
    puts s       
end

I have a bunch of subfolders within a directory and this snippet seems to go into some of the subdirectories, but skips most of them. How can I make it so that it recurses into all directories?

Also, should I be using Find instead? If so, could someone provide an example that does the same as above, namely finding .jpgs in all subdirectories?

EDIT -

Ok, so apparently when I do it with .JPG (capitalized) it finds all the files. Strange... How can I tell to find either of them?


Solution

  • This may help with different extensions:

    files = Dir[File.join(path, '**', '*.{jpg,JPG}')].each do |s| 
        puts s       
    end