I am preparing script that should check several subfolders and move file for processing based on FIFO to work dir.
My (very short, amateur) code looks like this now.
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 < 1 Then
Wscript.Quit
End If
If fso.GetFolder(trgtPath).Files.Count => 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 < oldestFile.DateLastModified Then
Set oldestFile = objFile
End If
End If
Next
oldestFile.Move trgtPath & "\" & oldestFile.Name
Wscript.Quit
I need this script to search all subfolders in trgtPath (c:\terms) and move only 1 oldest file to trgtPath. I tried
Set Subfldr = srcPath.Subfolders
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.
If you can please help me, I would be really grateful. Thank you in advance.
srcPath
is a string. srcFolder
is your Folder object. Use srcFolder.Files
instead.