单线程递归列出Ruby中的目录? [英] One-liner to recursively list directories in Ruby?
本文介绍了单线程递归列出Ruby中的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何包含文件?
解决方案
Dir.glob(** / * /)#用于目录
Dir.glob(** / *)#用于所有文件
而不是 Dir.glob(foo)
也可以写成 Dir [ foo]
(但是 Dir.glob
也可以占用一个块,在这种情况下,它将产生每个路径而不是创建一个数组) p>
What is the fastest, most optimized, one-liner way to get an array of the directories (excluding files) in Ruby?
How about including files?
解决方案
Dir.glob("**/*/") # for directories
Dir.glob("**/*") # for all files
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屋!
查看全文