What's the Ruby equivalent of Python's os.walk?

前端 未结 3 1899
逝去的感伤
逝去的感伤 2021-01-01 10:33

Does anyone know if there\'s an existing module/function inside Ruby to traverse file system directories and files? I\'m looking for something similar to Python\'s os

3条回答
  •  感情败类
    2021-01-01 11:28

    The following will print all files recursively. Then you can use File.directory? to see if the it is a directory or a file.

    Dir['**/*'].each { |f| print f }
    

提交回复
热议问题