单行递归列出 Ruby 中的目录? [英] One-liner to recursively list directories in Ruby?
本文介绍了单行递归列出 Ruby 中的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Ruby 中获取目录数组(不包括文件)的最快、最优化、单行方式是什么?
What is the fastest, most optimized, one-liner way to get an array of the directories (excluding files) in Ruby?
如何包含文件?
推荐答案
Dir.glob("**/*/") # for directories
Dir.glob("**/*") # for all files
代替 Dir.glob(foo)
你也可以写 Dir[foo]
(不过 Dir.glob
也可以带一个块,在这种情况下,它将产生每个路径而不是创建一个数组).
Instead of Dir.glob(foo)
you can also write Dir[foo]
(however Dir.glob
can also take a block, in which case it will yield each path instead of creating an array).
这篇关于单行递归列出 Ruby 中的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文