When I need to work with files in a given directory, I always resort to the following way, which to my opinion is cumbersome:
this_dir = Dir.pwd
filepath = File.join(this_dir, "directory")
file_list = Dir[File.join(filepath, "*.txt")]
I know that the code below returns an array of filenames. Supposedly there is only one file in that directory, the way I'm used to reaching to is:
File.basename(file_list[0])
Are there better and tidier ways to get a list of files in a directory, so that I can do whatever I want with these?