title: VBS - find oldest file in subfolders and move
body: <p>I am preparing script that should check several subfolders and move file for processing based on FIFO to work dir. </p>
  
  <p>My (very short, amateur) code looks like this now. </p>
  
  <pre><code>Dim srcPath,trgtPath,objFile,totalFiles,fso
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  srcPath = "C:\terms\"
  
  Set srcFolder = fso.GetFolder(srcPath)
  trgtPath = "C:\AutoTerm\Temp"
  
  If fso.GetFolder(srcPath).Files.Count &lt; 1 Then
  Wscript.Quit
  End If
  
  If fso.GetFolder(trgtPath).Files.Count =&gt; 1 Then
  Wscript.Quit
  End If
  
  
  Dim oldestFile, oldestDate
  For Each objFile In srcPath.Files
  If oldestFile = "" Then
  Set oldestFile = objFile
  Else
  If objFile.DateLastModified &lt; oldestFile.DateLastModified Then
  Set oldestFile = objFile
  End If
  End If
  Next
  
  oldestFile.Move trgtPath &amp; "\" &amp; oldestFile.Name
  
  Wscript.Quit
  </code></pre>
  
  <p>I need this script to search all subfolders in trgtPath (c:\terms) and move only 1 oldest file to trgtPath. I tried </p>
  
  <pre><code> Set Subfldr = srcPath.Subfolders
  </code></pre>
  
  <p>But it does not work, always asks for "object" and same result is when I tried to change For Each to folder and srcPath.Subfolders. </p>
  
  <p>If you can please help me, I would be really grateful. Thank you in advance. </p>