问题描述
在 Ruby 中,Dir.glob("**/*.rb")
(例如)不会遍历符号链接目录.是否可以让 **
遍历符号链接?
In Ruby, Dir.glob("**/*.rb")
(for instance) doesn't traverse symlinked directories. Is it possible to get the **
to traverse symlinks?
我正在使用两个 gems 以这种方式查找文件,但我需要它们来查看符号链接目录中的文件.
I'm using two gems which find files this way, but I need them to see files within a symlinked directory.
推荐答案
Jonathan 的聪明和狡猾的方法很棒,能够通过成群的符号链接进行削减,只需轻弹几个星号,哇哈哈.但是,它具有不返回直接子匹配项的不幸副作用.改进的版本可能是:
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.
这篇关于我可以使用“**"遍历 Ruby 中的符号链接目录吗?球?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!