Please Help my script wont work even after it executes correctly.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gatsby1124
    New Member
    • Sep 2007
    • 1

    #1

    Please Help my script wont work even after it executes correctly.

    [CODE=vb]' -----------------------------------------------------------------------------
    ' Aplica la politica de retencion de copias de backup en disco externo
    ' Menusal (M): Se guardan 6 meses
    ' Semanal o Full (F): Se guradan 2 meses
    ' Diario o Incremental (I): Se guardan 4 semanas
    ' -----------------------------------------------------------------------------

    On Error Resume Next

    dCurrentDate = Now

    a = ApplyPolicy("F: \Backups")
    a = ApplyPolicy("F: \Control")
    a = ApplyPolicy("F: \Logs")

    WScript.Quit 0

    ' -----------------------------------------------------------------------------
    ' Esta funcion aplica la politica de retencion de backup en disco externo
    ' -----------------------------------------------------------------------------
    Function ApplyPolicy(sFo lder)
    Dim oFS, oFP, oFiles, oFC

    Set oFS = CreateObject("S cripting.FileSy stemObject")
    sAbsFolder = oFS.GetAbsolute PathName(sFolde r)
    WScript.Echo "Processing " & sAbsFolder
    bRetVal = oFS.FolderExist s(sAbsFolder)
    Set oFP = oFS.GetFolder(s AbsFolder)
    Set oFiles = oFP.Files
    For each oFC in oFiles
    sFileName = oFC.Name
    sFilePrefix = Left(sFileName, 15)
    sFullFileName = oFS.BuildPath(s AbsFolder, sFileName)
    dBackupDate = oFC.DateCreated
    If sFilePrefix = "Backup_M_PlaTO N" Then
    If (Month(dBackupD ate) - Month(dCurrentD ate)) > 6 Then
    WScript.Echo " DEL => " & sFileName & " (" & dBackupDate & ")"
    b = oFS.DeleteFile( sFullFileName, true)
    Else
    WScript.Echo " Ok => " & sFileName & " (" & dBackupDate & ")"
    End If
    End If
    If sFilePrefix = "Backup_F_PlaTO N" Then
    If (Month(dBackupD ate) - Month(dCurrentD ate)) > 2 Then
    WScript.Echo " DEL => " & sFileName & " (" & dBackupDate & ")"
    b = oFS.DeleteFile( sFullFileName, true)
    Else
    WScript.Echo " Ok => " & sFileName & " (" & dBackupDate & ")"
    End If
    End If
    If sFilePrefix = "Backup_I_PlaTO N" Then
    If (dBackupDate - dCurrentDate) > 30 Then
    WScript.Echo " DEL => " & sFileName & " (" & dBackupDate & ")"
    b = oFS.DeleteFile( sFullFileName, true)
    Else
    WScript.Echo " Ok => " & sFileName & " (" & dBackupDate & ")"
    End If
    End If
    Next

    ApplyPolicy = bRetVal
    End Function[/CODE]

    Please can someone help me out I'm losing my hair over this situation.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    What situation? You haven't told us what the problem is.

    If it "executes correctly" then in what way can it be said to not work?

    Also, It might also help if you could fill in more detail about the script. Since you refer to it as a "script", this is in VBA, right? If so, in what application? If not, what version of VB is it?

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      After a quick glance at it I can at least give you one tip. Use the DateDiff() function to determine how far apart two dates are. The Month() function just returns a number between 1 and 12, which can produce strange results.

      For example, take these two dates...
      5th September 2007
      1st January 2008.

      The Month() function will simply return 9 and 1, respectively, which is pointless for comparison purposes. On the other hand, feed them into DateDiff() function and you can find out how far apart they are in...
      Years : 1 (I guess it rounds up)
      Months : 4
      Weeks : 16
      Days : 118
      Seconds : 10195200

      Comment

      • hariharanmca
        Top Contributor
        • Dec 2006
        • 1977

        #4
        I suggest every one to do not use

        [CODE=vb]On Error Resume Next[/CODE]It will not throw any error then; how can be possible to get what is the status?

        Better use

        [CODE=vb]On Error Goto ErrLable[/CODE]

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by hariharanmca
          I suggest every one to do not use [CODE=vb]On Error Resume Next[/CODE]
          Good point.

          I do sometimes use that statement, but generally because I want to be able to continue on and check Err.Number to see what happened. I believe this gives you something fairly similar to the new Try...Catch logic.

          Comment

          Working...