Hi, I have a little script that runs as a scheduled task The purpose of the task is to move the oldest files in a specific directory into a new directory. This works as expected when there are files in the directory. However if there are no files in the directory then I get an error message. Attached below is the script that I have used.
Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\MAS\Company\")
Set colFiles = objFolder.Files
dtmOldestDate = Now
For Each objFile in colFiles
If objFile.DateCreated < dtmOldestDate Then
dtmOldestDate = objFile.DateCreated
strOldestFile = objFile.Path
objFSO.MoveFile strOldestFile, ("C:\MAS\Company\FTP\")
Any help would be much appreciated.