title: Ruby: Using a regular expression to find and open a file based on its filename?
body: <p>I am trying to test the contents of a file that is generated from code. The problem is that the full name of the file is based on a timestamp <code>abc123_#{d.strftime('%Y%m%d%I%M%S')}.log</code></p>
  
  <p>How could I use <code>File</code> to find this file and read it? I tried doing <code>File.exists?()</code> with a regular expression as the parameter but that didn't work. </p>
  
  <p>I found this in another question on stackoverflow:</p>
  
  <p><code>File.basename(file_path).match(/_.*(css|scss|sass)/)</code></p>
  
  <p>How would I be able to use that in my case where the file is located in my<code>public</code> folder?</p>
  
  <p><strong>ANSWER</strong></p>
  
  <p>So the two answers below both work and I used a combination of them.</p>
  
  <p><code>Dir['public/*.log'].select { |f| f =~ /purge_cc_website/}</code></p>
  
  <p>The <code>*</code> acts as a wildcard that is sort of a regular expression in itself. After that you filter the array using an actual regex.</p>