i try to find all files in a directory which has a name like "test".
So in my directory (/test/files/example) i got following files:
How can i get all the files with the File Class in Ruby? I do this but i think you see the struggle
10.times do |count|
file_path = "/test/files/example/test_#{count}.wav"
if File.exist?(file_path)
@files[count] = file_path
next
end
break
end
Globbing is the way to go. This will return an array of filenames matching your pattern.
Dir["/test/files/example/test_*.wav"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With