title: Identify and Copy latest files in directory
body: <p>Everyday around 7 AM there are <strong>3</strong> csv exports extracted into a specific folder and the file names are exactly the same each day except everyday the prefix of the file name is amended to the current date. </p>
  
  <p>Example: </p>
  
  <p><strong>16-02-2018_Test1</strong> will change to <strong>17-02-2018_Test1</strong> </p>
  
  <p><strong>16-02-2018_Test2</strong> will change to <strong>17-02-2018_Test2</strong> </p>
  
  <p><strong>16-02-2018_Test3</strong> will change to <strong>17-02-2018_Test3</strong> </p>
  
  <p>The file itself is not replaced, the new file with the current date is instead added to this folder.</p>
  
  <p>What I need to do is identify the 3 extracts each day and copy them to a sub-folder. The best way I thought of doing this is by identifying the date at which the file was last modified.</p>
  
  <p>I have the below VBS code I found and helps identifies the latest file in a directory and I added a line that will copy that file to a new directory. </p>
  
  <p>The issue however, is that the code only identifies 1 file instead of 3 and I can only copy 1 file instead of 3. If anyone has better code to help me achieve the desired result <strong>or</strong> alternatively can help modify the existing code to achieve the desired result.</p>
  
  <pre><code>sPath = "C:\Users\Desktop\Test\"
  
  Const sToDir = "C:\Users\Desktop\Test\NewFolder\"
  
  Set oFSO = CreateObject("Scripting.FileSystemObject")
  
  sNewestFile = GetNewestFile(sPath)
  
  If sNewestFile &lt;&gt; "" Then
  
     WScript.Echo "Newest file is " &amp; sNewestFile
  
     dFileModDate = oFSO.GetFile(sNewestFile).DateLastModified
     If DateDiff("n", dFileModDate, Now) &gt; 60 Then
       oFSO.CopyFile sNewestFile, sToDir
     End If
  
  Else
     WScript.Echo "Directory is empty"
  End If
  
  
  Function GetNewestFile(ByVal sPath)
  
     sNewestFile = Null   ' init value
  
     Set oFSO = CreateObject("Scripting.FileSystemObject")
     Set oFolder = oFSO.GetFolder(sPath)
     Set oFiles = oFolder.Files
  
     ' enumerate the files in the folder, finding the newest file
     For Each oFile In oFiles
       On Error Resume Next
       If IsNull(sNewestFile) Then
         sNewestFile = oFile.Path
         dPrevDate = oFile.DateLastModified
       Elseif dPrevDate &lt; oFile.DateLastModified Then
         sNewestFile = oFile.Path
         dPrevDate = oFile.DateLastModified
       End If
       On Error Goto 0
     Next
  
     If IsNull(sNewestFile) Then sNewestFile = ""
  
     GetNewestFile = sNewestFile
  
  End Function
  </code></pre>