title: search files with date pattern names in c# based on date range
body: <p>I have some files with this pattern:</p>
  
  <p>PrefixyyyyMMddHHmmss.txt</p>
  
  <p>That Prefix is always the same.</p>
  
  <p>For example :
  Prefix20120830115800.txt</p>
  
  <p>Prefix20120829114200.txt</p>
  
  <p>Prefix20120829134621.txt</p>
  
  <p>I want to write a function to get one day and range and returns all files that their names are in input range from that day:</p>
  
  <pre><code>ReadFiles(string filesLocation, DateTime fromDate, int range)
  </code></pre>
  
  <p>Now I use this approach:</p>
  
  <pre><code>for (int i = 0; i &lt;= range; i++)
  {
      SearchFolderForFiles(location, fromDate.AddDays(i));
  }
  
  SearchFolderForFiles(//params)
  {
  //…
    string searchTemplate = string.Format("Prefix{0:yyyyMMdd}*.txt", date);
    DirectoryInfo di = new DirectoryInfo(location);
    FileInfo[] myFiles = di.GetFiles(searchTemplate);
  //…
  }
  </code></pre>
  
  <p>But I think it should be better way(specially we have range not separated days)</p>
  
  <p>Thanks</p>