Hoping someone can help on the below script, basically, when it runs, it echo's all the files but does not then delete anything or echo the file name at the section when it checks if its a full.
Basically what I am trying to achieve is to write a script to delete files after a certain filename, so based on the below file list
FILE_000001_FULL.ZIP
FILE_000002_FULL.ZIP
FILE_000003_FULL.ZIP
FILE_000004_FULL.ZIP
FILE_000005_FULL.ZIP
FILE_000006_DELTA.ZIP
FILE_000007_DELTA.ZIP
FILE_000008_FULL.ZIP
Everything up until FILE_000005_FULL.ZIP would be deleted. The files are created using a tool and will be sorted by file name, so highest number first. Basically need the 2 latest FULL files kept and the DELTA's (if any) between them. I hope that makes sense.
Cheers for any help in advance!
Code:
Option Explicit
Dim intNum, intMax2, intMax1, FSO, File, str
Set FSO = CreateObject("Scripting.FileSystemObject")
str = (Left(File.Name, 4))
' First pass: Find the two latest FULLs...
For Each File In FSO.GetFolder("c:\mds").Files
wscript.echo File.Name
wscript.echo str
' Is this a FULL?
If Right(File.Name, 8) = "FULL.ZIP" Then
wscript.echo File.Name
' Get the numeric value from the file name (6 digits starting as pos 6)...
intNum = CLng(Mid(File, 6, 6))
wscript.echo intNum
' Maintain the two latest FULLs...
If intNum > intMax1 Then
intMax2 = intMax1
intMax1 = intNum
ElseIf intNum > intMax2 Then
intMax2 = intNum
End If
End If
Next
' Second pass: Delete anything prior to the second-latest FULL...
For Each File In FSO.GetFolder("c:\mds").Files
intNum = CLng(Mid(File.Name, 6, 6))
If intNum < intMax2 Then File.Delete
Next
king edwards
Basically what I am trying to achieve is to write a script to delete files after a certain filename, so based on the below file list
FILE_000001_FULL.ZIP
FILE_000002_FULL.ZIP
FILE_000003_FULL.ZIP
FILE_000004_FULL.ZIP
FILE_000005_FULL.ZIP
FILE_000006_DELTA.ZIP
FILE_000007_DELTA.ZIP
FILE_000008_FULL.ZIP
Everything up until FILE_000005_FULL.ZIP would be deleted. The files are created using a tool and will be sorted by file name, so highest number first. Basically need the 2 latest FULL files kept and the DELTA's (if any) between them. I hope that makes sense.
Cheers for any help in advance!