Get names of all files from a folder with Ruby

后端 未结 19 2417
[愿得一人]
[愿得一人] 2020-11-29 14:57

I want to get all file names from a folder using Ruby.

19条回答
  •  旧时难觅i
    2020-11-29 15:42

    This is what works for me:

    Dir.entries(dir).select { |f| File.file?(File.join(dir, f)) }
    

    Dir.entries returns an array of strings. Then, we have to provide a full path of the file to File.file?, unless dir is equal to our current working directory. That's why this File.join().

提交回复
热议问题