title: How do I get the supplied VBScript to copy files for my folders?
body: <p>I want to find the most recent folder and copy files to destination folder with vbsscript.</p>
  
  <p>This is done <a href="https://stackoverflow.com/questions/15577945/vb-script-find-most-recent-folder-copy-files-to-destination-folder?rq=1">here on SO</a>, but the solution provided does not work for me.</p>
  
  <p>Ansgar Wiechers provided this code.</p>
  
  <pre><code>rootFolder = "C:\root"
  dstFolder  = "C:\dst"
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  Set mostRecent = FindMostRecent(fso.GetFolder(rootFolder))
  For Each f In mostRecent
    f.Copy fso.BuildPath(dstFolder, f.Name)
  Next
  
  Function FindMostRecent(fldr)
    Set mrf = fldr
    For Each sf In fldr.SubFolders
      Set mrsf = FindMostRecent(sf)
      If mrsf.DateLastModified &gt; mrf.DateLastModified Then Set mrf = mrsf
    Next
    Set FindMostRecent = mrf
  End Function
  </code></pre>
  
  <p>When changing first line to <code>rootFolder = "D:\"</code> and second to
  <code>dstFolder  = "C:\"</code>, I get the following error:</p>
  
  <pre><code>Script: C:\Users\xxx\Desktop\new 456 82.vbs
  Line:   14
  Char:   5
  Error:  Object required: 'FindMostRecent(...)'
  Code:   800A01A8
  Source:     Microsoft VBScript runtime error
  </code></pre>
  
  <p>Changing root to <code>D:\Files</code> and destination to <code>C:\test</code> gives:</p>
  
  <pre><code>Script: C:\Users\Bradley\Desktop\new 456 8.vbs
  Line:   7
  Char:   1
  Error:  Object doesn't support this property or method
  Code:   800A01B6
  Source:     Microsoft VBScript runtime error
  </code></pre>
  
  <p>I have not yet incorporated the <code>copy</code> command found in the same thread:</p>
  
  <pre><code>cls set knownpath=C:\a for /f "delims=" %%a in ('dir /ad /od /b "%knownpath%"') do ( set name=%%a )         copy "%knownpath%\%name%" "C:\b"
  </code></pre>
  
  <p>I have no idea where in the script I should place the command.  I tried right after <code>Set FindMostRecent = mrf</code> on a new line, but I get another error.  Tried after <code>End</code> function too, and get another error. </p>
  
  <p>I need this broken down to me as if I was a five year old.</p>
  
  <p>edit: ok so now that the main code is working I'm trying to insert the copy command. This is what I tried so far and it's giving me error.</p>
  
  <pre><code>    rootFolder = "D:\test"
      dstFolder  = "D:\test2"
  
      Set fso = CreateObject("Scripting.FileSystemObject")
  
      Set mostRecent = FindMostRecent(fso.GetFolder(rootFolder))
      For Each f In mostRecent.Files
        f.Copy fso.BuildPath(dstFolder, f.Name)
      Next
  
      Function FindMostRecent(fldr)
        Set mrf = fldr
        For Each sf In fldr.SubFolders
          Set mrsf = FindMostRecent(sf)
          If mrsf.DateLastModified &gt; mrf.DateLastModified Then Set mrf = mrsf
        Next
        Set FindMostRecent = mrf
      End Function
      cls set knownpath="D:\test" for /f "delims=" %%a in ('dir /ad /od /b "%knownpath%"') do ( set name=%%a ) copy "%knownpath%\%name%" "D:\test2" 
  </code></pre>
  
  <p>EDIT2: </p>
  
  <pre><code>rootFolder = "D:\Files"
  dstFolder  = "D:\test"
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  Set mostRecent = FindMostRecent(fso.GetFolder(rootFolder))
  mostRecent.Copy dstFolder
  
  Function FindMostRecent(fldr)
    Set mrf = fldr
    For Each sf In fldr.SubFolders
      Set mrsf = FindMostRecent(sf)
      If mrsf.DateLastModified &gt; mrf.DateLastModified Then Set mrf = mrsf
    Next
    Set FindMostRecent = mrf
  End Function
  </code></pre>