|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
VB Script to delete old DB backup files
I have a script that i used to delete old database back up files that are older than 3 days old and it works if it is in the same folder as the back ups but sems to delete itself once it is 3 days old the code is below. the Script is in this directory: L:\ and the back up files are located in L:\DB Backups
I am trying to run the script using windows scheduled tasks but it does not seem to be working and i can not figure it out the code is below. perhaps it is something in my scheduled task settings but as i said it worked when the file was in the same folder as the backups Option Explicit on error resume next Dim oFSO Dim sDirectoryPath Dim oFolder Dim oFileCollection Dim oFile Dim iDaysOld 'Customize values here to fit your needs iDaysOld > 3 Set oFSO = CreateObject("Scripting.FileSystemObject") sDirectoryPath = "L:\DB Backups" set oFolder = oFSO.GetFolder(sDirectoryPath) set oFileCollection = oFolder.Files 'Walk through each file in this folder collection. 'If it is older than 3 days, then delete it. For each oFile in oFileCollection If oFile.DateLastModified < (Date() - iDaysOld) Then oFile.Delete(True) End If Next 'Clean up Set oFSO = Nothing Set oFolder = Nothing Set oFileCollection = Nothing Set oFile = Nothing ![]() |
|
#2
|
|||
|
|||
|
You should test the filename to make sure you're not deleting the script file itself.
__________________
====== Doug G ====== "Hide, hide witch! The good folk come to burn thee. Their keen enjoyment hid behind their gothic mask of duty." -Mark Clifton |
|
#3
|
|||
|
|||
|
Quote:
I think that is what is happening. Is there some way that i can restrict the script to say: if filename = delete_old_files.vbs then skip it? |
|
#4
|
|||
|
|||
|
Quote:
Code:
' skeleton for example only, and there are better ways to structure this test If sFilename = "the_file_i_want_to_save.vbs" Then ' Do nothing Else 'delete the file End if |
|
#5
|
||||
|
||||
|
or to get rid of the other condition just...
Code:
If sFilename <> "the_file_i_want_to_save.vbs" Then
'delete the file
End if
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > VB Script to delete old DB backup files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|