开发者

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 th开发者_开发百科at 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?


This may help with different extensions:

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


Obviously you forgot use glob method on Dir like:

 Dir.glob(File.join('**','*.jpg'))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜