Hi,
A directory contains X files of which one or more follow the patern abc*.* . I need a script to see if more than one file follow that patern and if so, the most recent file has to be left alone, the rest has to be deleted.
Thanks for your help!
Set objFolder = FSO.GetFolder("c:\test")
intCounter = 0
datModified = 0
For Each aFile In objFolder.Files
If LCase(Left(aFile.Name)) = "abc" Then
If intCounter > 1 Then
'we have more than one abc file
If aFile.DateModified > datModified Then
datModified = aFile.DateLastModified
strNewestFile = aFile.Name
Else
aFile.Delete
End If
Else
datModified = aFile.DateLastModified
strNewestFile = aFile.Name
End If
intCounter = intCounter + 1
End If
Next
might help you, might even work but its a bit early in the day for me!! ;-)
Thanks for your help mrmovie, had to make a change here and there but you certainly set me off in the right direction. Thanks!!
FYI, the changed code:
Set FSO = createobject("Scripting.FileSystemObject")
Set objFolder = FSO.GetFolder("c:\test")
intCounter = 0
datModified = 0
For Each aFile In objFolder.Files
If LCase(Left(aFile.Name,3)) = "abc" Then
If intCounter > 0 Then
'we have more than one abc file
If aFile.DateLastModified > datModified Then
FSO.DeleteFile(objFolder & "\" & strNewestFile)
datModified = aFile.DateLastModified
strNewestFile = aFile.Name
Else
aFile.Delete
End If
Else
datModified = aFile.DateLastModified
strNewestFile = aFile.Name
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.