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

大兔子大兔子 提交于 2019-11-28 21:17:11

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.

Normally not with recursive search due to the risk of infinite loops.

But, this discussion may help:

Dir.glob("**/*/**/b") will follow a symlink up to once.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!