Is there any class in ruby for开发者_开发技巧 listing all the files in a directory and all the files in the subdirectory?
You might look at Dir.glob
. You can pass it the **/*
path which will give you everything in the folder and its subdirectories:
records = Dir.glob("path/to/your/root/directory/**/*")
# Will return everything - files and folders - from the root level of your root directory and all it's subfolders
# => ["file1.txt", "file2.txt", "dir1", "dir1/file1.txt", ...]
Since you probably want a list of files, excluding folders, you can use:
records = Dir.glob("path/to/your/root/directory/**/*").reject { |f| File.directory?(f) }
精彩评论