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.
如何从目录中获取前 N 个文件?
我尝试通过以下方式遍历文件
Dir.glob(expression).do |f| i = i + 1 files.push(f) if (i == 5) then break # illegal end end
但是放入break该then子句显然是非法的。
break
then
谢谢!
Dir.glob(expression).first(5)
这将从目录中获取前 5 个文件。
这是否可以接受:
MAX = 5 Dir.glob(expression)[0..MAX-1]