0

I have many files in the folder, such as mp4, mov, avi files. But I have to find files that are end with "_college.mp4".

I tried following way

File.exists?("#{temp_dir}/*_college.mp4")

But I not worked. How can I do this in ruby.

r15
  • 486
  • 1
  • 8
  • 22

2 Answers2

3

You should use Dir::glob method :

Dir.glob("#{temp_dir}/*_college.mp4")
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
3

@ArupRakshit answered perfectly. I would like to add:

You can even use the shorthand Dir[] for #glob shorthand:

Dir["#{temp_dir}/*_college.mp4"]
Community
  • 1
  • 1
kiddorails
  • 12,961
  • 2
  • 32
  • 41