Can I traverse symlinked directories in Ruby with a “**” glob?

后端 未结 2 1666
南旧
南旧 2020-12-14 17:27

In Ruby, Dir.glob(\"**/*.rb\") (for instance) doesn\'t traverse symlinked directories. Is it possible to get the ** to traverse symlinks?

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 18:16

    Jonathan's clever and cunning approach is great, capable of slashing through hordes of symlinks with but a mere flick of a few asterisks, muahaha. However, it has the unfortunate side-effect of not returning immediate-child matches. An improved version might be:

    Dir.glob("**{,/*/**}/*.rb")
    

    Which will (in my tests) do both follow one symlink and return immediate children.

提交回复
热议问题