Log Cleanup..

Home Forums Scripting General Scripting Log Cleanup..

  • This topic has 3 replies, 4 voices, and was last updated 13 years ago by AvatarLan.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    Lemons
    Member
    #127606

    I have searched and there was no real vbscript resolution for my issue.. I cant use Robocopy.

    Basically what I want is a script that will delete files in a folder of a specific name that are older then a certain number of days.

    This is what I have so far, and it’s probably something simple but I’m new to vbscript and cant get it to work.
    Option Explicit

    Dim MyArray(2)

    MyArray(0)=”OrderAudit-.log”
    MyArray(1)=”Info-.log”
    MyArray(2)=”Debug.log”

    Dim f1
    Dim ret_time
    Dim fso
    Dim oFolder
    Dim oFile
    Dim sDirectoryPath
    Dim index, x

    Set fso = createobject(“Scripting.FileSystemObject”)
    sDirectoryPath = “D:_awcgatewayarchive”
    Set oFolder = fso.GetFolder(sDirectoryPath)
    ret_time = 1

    For Each oFile In oFolder.files
    If DateDiff(“d”, oFile.datelastmodified,Now) > ret_time Then
    index = 0
    For x = 0 To UBound(MyArray)
    If LCase(oFile.Name) = LCase(MyArray(x)) Then
    index = 1
    Exit For
    End If

    Next
    If index = 1 Then
    oFile.Delete True
    Else
    End if
    End If
    Next

    Set oFolder = Nothing
    Set fso = Nothing[/CODE]
    So basically any help would be much appreciated!

    [COLOR=”Green”]Edit Dumber:
    Wrapped Code tags arround the script.[/COLOR][CODE]Option Explicit

    Dim MyArray(2)

    MyArray(0)=”OrderAudit-.log”
    MyArray(1)=”Info-.log”
    MyArray(2)=”Debug.log”

    Dim f1
    Dim ret_time
    Dim fso
    Dim oFolder
    Dim oFile
    Dim sDirectoryPath
    Dim index, x

    Set fso = createobject(“Scripting.FileSystemObject”)
    sDirectoryPath = “D:_awcgatewayarchive”
    Set oFolder = fso.GetFolder(sDirectoryPath)
    ret_time = 1

    For Each oFile In oFolder.files
    If DateDiff(“d”, oFile.datelastmodified,Now) > ret_time Then
    index = 0
    For x = 0 To UBound(MyArray)
    If LCase(oFile.Name) = LCase(MyArray(x)) Then
    index = 1
    Exit For
    End If

    Next
    If index = 1 Then
    oFile.Delete True
    Else
    End if
    End If
    Next

    Set oFolder = Nothing
    Set fso = Nothing[/CODE]
    So basically any help would be much appreciated!

    Edit Dumber:
    Wrapped Code tags arround the script.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.