So Sidewinder helped me create a .bat and .vbs script that work like a charm. But now I need to modify it to delete all .zip files older than a week old. I have tried various methods and i seen the main method is to use forfiles but i can not install that on any computers. So doing it via batch would be perfect if i have to use another .vbs script that is fine to but prefer .bat
Batch file code
@echo Backing up your Database....This may take awhile.....
sqlcmd -S ServerName -i backupDBscript.sql
SET MY_Path=pathtofiles
set mydate=%date:~4,2%%date:~7,2%%date:~10,4%
for %%x in (*.bak) do cscript "%MY_PATH%\zip.vbs" "%MY_PATH%\%%x" "%MY_PATH%\DB_%mydate%.zip"
del "%MY_PATH%\*.bak
exit
.vbs file to compress database
Set oFSO = CreateObject("Scripting.FileSystemObject")
ToZip = oFSO.GetAbsolutePathName(WScript.Arguments.Item(0))
ZipName = oFSO.GetAbsolutePathName(WScript.Arguments.Item(1))
d=WindowsZip(ToZip, ZipName)
Function WindowsZip(sFile, sZipFile)
Set oZipShell = CreateObject("WScript.Shell")
Set oZipFSO = CreateObject("Scripting.FileSystemObject")
If Not oZipFSO.FileExists(sZipFile) Then
NewZip(sZipFile)
End If
Set oZipApp = CreateObject("Shell.Application")
sZipFileCount = oZipApp.NameSpace(sZipFile).items.Count
aFileName = Split(sFile, "\")
sFileName = (aFileName(Ubound(aFileName)))
sDupe = False
For Each sFileNameInZip In oZipApp.NameSpace(sZipFile).items
If LCase(sFileName) = LCase(sFileNameInZip) Then
sDupe = True
Exit For
End If
Next
If Not sDupe Then
wscript.echo "Adding " & sfile
oZipApp.NameSpace(sZipFile).Copyhere sFile
On Error Resume Next
Do Until sZipFileCount < oZipApp.NameSpace(sZipFile).Items.Count
Wscript.Sleep(100)
Loop
On Error GoTo 0
End If
End Function
Sub NewZip(sNewZip)
Set oNewZipFSO = CreateObject("Scripting.FileSystemObject")
Set oNewZipFile = oNewZipFSO.CreateTextFile(sNewZip)
oNewZipFile.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
oNewZipFile.Close
Set oNewZipFSO = Nothing
Wscript.Sleep(500)
End Sub