2marshall8
Technical User
I am need of finding the newest file within a directory and assigning this to a variable which I can then use to send via email to myself. I found this script on the net which helps in finding the newest file in a specified directory but I'm not able to fix the error that occurs. I know this must be easy but my vbs knowledge isn't upto par like marcdmac's and a few of the rest of ya.
The error I receive is on line 13, character 25. and the reason is Invalid character.
thanks for any help you can provide.
Code:
Dim fsoFile 'As File
Dim fsoFolder 'As Folder
Dim dOldDate 'As Date
Dim strFileName 'As String
Dim fso 'As FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoFolder = fso.GetFolder("C:\")
For Each fsoFile In fsoFolder.Files
Select Case Left$(fsoFile.Name, 10)
Case "XYZ_123_A-"
If DateDiff("s", dOldDate, fsoFile.DateCreated) > 0 Then
dOldDate = fsoFile.DateCreated
strFileName = fsoFile.Name
End If
End Select
Next
Set fsoFile = Nothing
Set fsoFolder = Nothing
Set fso = Nothing
'After loop is done strFileName will hold the newest file in the folder
'for files beginning with "XYZ_123_A-"
'dOldDate will hold the date it was created
The error I receive is on line 13, character 25. and the reason is Invalid character.
thanks for any help you can provide.