Search code examples
rubyruby-1.9.3ruby-1.9

Find the file in the folder with specific end in ruby


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.


Solution

  • You should use Dir::glob method :

    Dir.glob("#{temp_dir}/*_college.mp4")