Get names of all files from a folder with Ruby

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

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

19条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 15:32

    In an IRB context, you can use the following to get the files in the current directory:

    file_names = `ls`.split("\n")
    

    You can make this work on other directories too:

    file_names = `ls ~/Documents`.split("\n")
    

提交回复
热议问题