title: Copy file(s) by order using .NET System.IO File.Copy
body: <p>I'm creating a basic file copy operation in windows application. I noticed <code>System.IO File.Copy</code> copy files randomly.
  Is there a way to control what files should be copied first. For example If we want to copy files starting from smallest to largest file size. Or by Alphabetical order, lets say start copying files with filename [starting from] A to Z, or by numerical order with filename [from] 1 to 100.</p>
  
  <p>I'm using this simple code to copy files from a folder, but this copies files "randomly". See below:</p>
  
  <pre><code>Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
      Dim source as string = "c:\copyfiles"
      Dim destination as string = "d:\backup"
      Dim filepath as string = destination &amp; "\"
  
          For Each filename As String In Directory.GetFiles(source)
              If File.Exists(filename) Then
                  Dim dFile As String = String.Empty
                  Dim dFilePath As String = String.Empty
  
                  dFile = Path.GetFileName(filename)  'get filenames from source
                  dFilePath = filepath &amp; dFile  'concatenate filepath and filename
  
                  File.Copy(filename, dFilePath, True) 'copy files from "c:\copyfiles" folder to destination
              End If
  
          Next
          MsgBox("Copy Successful", vbOKOnly, "Message")
  End Sub
  </code></pre>