-1

I need to find a file somewhere in in the file system. I'll know the base folder to start looking for and the file name, but I'm not sure how to find it.

This would be dynamically done as part of the code, just like when using FileUtils or Dir.glob.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Jason Logsdon
  • 507
  • 5
  • 19
  • "[Stack Overflow question checklist](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist)" is your friend. – the Tin Man Nov 30 '19 at 22:15
  • That's a similar question, and the answer helps out, but I wasn't looking for files of a certain extension and it never came up in my searching for an answer – Jason Logsdon Dec 01 '19 at 18:27
  • If you read the documentation for the methods you'll see that the exact extension can easily be changed and there are wildcards to allow you to ignore extensions or snoop inside the filename, look at particular attributes of the files, depending on which way you go about finding the files. It's not a simple subject and there are lots of gotchas to be aware of, and research and reading is important because picking the wrong path can degrade your script, or the host's, performance. – the Tin Man Dec 06 '19 at 21:48
  • Also, your question was poorly asked, hence my link to the checklist. On SO, we expect you to show us what you tried: Did you search? Where? Why didn't it help? If it helped, what did you try? If you didn't try, why not? If you did, what did you try? What happened then? As is your question was extremely broad and a general duplicate. Searching for files is well covered in that linked question. – the Tin Man Dec 06 '19 at 21:51
  • Cool. I would have preferred a simple answer to the question like Nezir gave, but I appreciate you taking the time to criticize the question. – Jason Logsdon Dec 07 '19 at 22:03

2 Answers2

0

Did you tried something like:

Dir.glob("#{root_folder}/**/*.file_extension")
Nezir
  • 6,727
  • 12
  • 54
  • 78
-1

It looks like the Ruby Find module may help you out. Its find method lets you iterate through all files in a directory.

See the answers in "Ruby function list file recursively" for some other approaches to a related issue.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Alexandra
  • 29
  • 4