By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

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

P: 1
Expand|Select|Wrap|Line Numbers
  1. ' -----------------------------------------------------------------------------
  2. ' Aplica la politica de retencion de copias de backup en disco externo
  3. ' Menusal (M): Se guardan 6 meses
  4. ' Semanal o Full (F): Se guradan 2 meses
  5. ' Diario o Incremental (I): Se guardan 4 semanas
  6. ' -----------------------------------------------------------------------------
  7.  
  8. On Error Resume Next
  9.  
  10. dCurrentDate = Now
  11.  
  12. a = ApplyPolicy("F:\Backups")
  13. a = ApplyPolicy("F:\Control")
  14. a = ApplyPolicy("F:\Logs")
  15.  
  16. WScript.Quit 0
  17.  
  18. ' -----------------------------------------------------------------------------
  19. ' Esta funcion aplica la politica de retencion de backup en disco externo
  20. ' -----------------------------------------------------------------------------
  21. Function ApplyPolicy(sFolder)
  22.    Dim oFS, oFP, oFiles, oFC
  23.  
  24.    Set oFS = CreateObject("Scripting.FileSystemObject")
  25.    sAbsFolder = oFS.GetAbsolutePathName(sFolder)
  26.    WScript.Echo "Processing " & sAbsFolder
  27.    bRetVal = oFS.FolderExists(sAbsFolder)
  28.    Set oFP = oFS.GetFolder(sAbsFolder)
  29.    Set oFiles = oFP.Files
  30.    For each oFC in oFiles
  31.       sFileName = oFC.Name
  32.       sFilePrefix = Left(sFileName, 15)
  33.       sFullFileName = oFS.BuildPath(sAbsFolder, sFileName)
  34.       dBackupDate = oFC.DateCreated
  35.       If sFilePrefix = "Backup_M_PlaTON" Then
  36.          If (Month(dBackupDate) - Month(dCurrentDate)) > 6 Then
  37.             WScript.Echo " DEL => " & sFileName & " (" & dBackupDate & ")"
  38.             b = oFS.DeleteFile(sFullFileName, true)
  39.          Else
  40.             WScript.Echo "  Ok => " & sFileName & " (" & dBackupDate & ")"
  41.          End If
  42.       End If
  43.       If sFilePrefix = "Backup_F_PlaTON" Then
  44.          If (Month(dBackupDate) - Month(dCurrentDate)) > 2 Then
  45.             WScript.Echo " DEL => " & sFileName & " (" & dBackupDate & ")"
  46.             b = oFS.DeleteFile(sFullFileName, true)
  47.          Else
  48.             WScript.Echo "  Ok => " & sFileName & " (" & dBackupDate & ")"
  49.          End If
  50.       End If
  51.       If sFilePrefix = "Backup_I_PlaTON" Then
  52.          If (dBackupDate - dCurrentDate) > 30 Then
  53.             WScript.Echo " DEL => " & sFileName & " (" & dBackupDate & ")"
  54.             b = oFS.DeleteFile(sFullFileName, true)
  55.          Else
  56.             WScript.Echo "  Ok => " & sFileName & " (" & dBackupDate & ")"
  57.          End If
  58.       End If
  59.    Next
  60.  
  61.    ApplyPolicy = bRetVal
  62. End Function
Please can someone help me out I'm losing my hair over this situation.
Sep 4 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
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?
Sep 6 '07 #2

Expert 5K+
P: 8,434
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
Sep 6 '07 #3

hariharanmca
100+
P: 1,977
I suggest every one to do not use

Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
It will not throw any error then; how can be possible to get what is the status?

Better use

Expand|Select|Wrap|Line Numbers
  1. On Error Goto ErrLable
Sep 6 '07 #4

Expert 5K+
P: 8,434
I suggest every one to do not use
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
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.
Sep 6 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.