Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Ruby 中,Dir.glob("**/*.rb")(例如)不遍历符号链接目录。是否有可能获得**遍历符号链接?
Dir.glob("**/*.rb")
**
我正在使用两个以这种方式查找文件的 gem,但我需要它们查看符号链接目录中的文件。
乔纳森聪明而狡猾的方法非常棒,只需轻弹几个星号就可以削减成群的符号链接,muahaha。但是,它具有不返回直接子匹配项的不幸副作用。改进的版本可能是:
Dir.glob("**{,/*/**}/*.rb")
哪个(在我的测试中)会遵循一个符号链接并返回直接的孩子。
由于存在无限循环的风险,通常不使用递归搜索。
但是,这个讨论可能会有所帮助:
Dir.glob("**/*/**/b")将遵循一个符号链接最多一次。
Dir.glob("**/*/**/b")