title: Deleting file if not just created (or being used)
body: <p>I am creating a console app that will delete pictures from a directory every 30 minutes. Problem is that its being populated by files every minute or so. So if I go and delete files in that directory then it may cause an error trying to delete a file thats being created just then or opened.</p>
  
  <p>I currently have this code to copy the files to another directory and then delete them from the source directory.</p>
  
  <pre><code>Dim f() As String = Directory.GetFiles(sourceDir)
  
      For i As Integer = 0 To UBound(f)
          'Check file date here in IF statement FIRST...
  
          File.Copy(f(i), destDir &amp; f(i).Replace(sourceDir, ""))
  
          If File.Exists(f(i)) = True Then
                File.Delete(f(i))
          End If
  
          Debug.Print(f(i) &amp; " to &gt;&gt;&gt; " &amp; destDir &amp; f(i).Replace(sourceDir, ""))
      Next
  </code></pre>
  
  <p>How can I use:</p>
  
  <pre><code>File.GetCreationTime(f(i))
  </code></pre>
  
  <p>in an IF statement checking IF the currently file its on is newer than 30 seconds ago?</p>
  
  <p><strong>OR</strong></p>
  
  <p>Is there a way of only populating:</p>
  
  <pre><code> Dim f() As String = Directory.GetFiles(sourceDir)
  </code></pre>
  
  <p>with only those files that are more than 30 seconds old?</p>