0

I have a script that works perfectly for me to move files, create new folders then delete out old ones, however i am unable to add in a zipping function. I can do this separately but would like it in my script as i only want to run the one scheduled task. Can anyone help?

Dim theDate, ArchiveDate
Dim CurPath
Dim BackupPath
Dim objFSO, objFolder, objFile
Dim ArchivePath


'theDate = InputBox("Date to archive (ddmmyy)")
theDate = DateAdd("d",-1, date())
dateArray = Split(theDate,"/")
theDate = dateArray(0) & dateArray(1) & Right(dateArray(2),2)

CurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
BackupPath = CurPath & "\" & thedate
ArchiveDate = CDate(left(theDate,2) & "/" & mid(theDate,3,2) & "/" & right(theDate,2))
ArchivePath = "E:\Log_Folder_1"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(CurPath)


'msgbox CurPath
'msgbox BackupPath
'msgbox ArchiveDate

For Each objFile In objFolder.Files
  ModifiedDate = Split(objFile.DateLastModified," ")  
  If (CDate(ModifiedDate(0)) = ArchiveDate AND objFSO.GetExtensionName(objFile) <> "vbs") Then
     'msgbox "yes " & objFile.DateLastModified
     If objFSO.FolderExists(BackupPath) = false Then
        objFSO.CreateFolder(BackupPath)
     End If
     objFile.Move BackupPath & "\" & objFile.Name
  Else
      'msgbox "no " & objFile.DateLastModified
  End If
Next


dim filesys 
set filesys=CreateObject("Scripting.FileSystemObject") 
If filesys.FolderExists(BackupPath) Then 
filesys.CopyFolder "E:\Log_Folder_1" & "\" & thedate,     "\\Backup_Server\Logs\Log_Folder_1"
End If 

If objFSO.FolderExists(CurPath & "\" & theDate) Then
    Set delFolder = objFSO.GetFolder(CurPath & "\" & theDate)
    delFolder.Delete
End If


Dim keepDays
keepDays = -20
Do Until keepDays=-10
theDate = replace(DateAdd("d",keepDays, date()),"/","")
theDate = left(theDate,4) & right(theDate,2)
If objFSO.FolderExists ("\\Backup_Server\Logs\Log_Folder_1" & "\" & theDate)     Then
  Set delFolder = objFSO.GetFolder("\\Backup_Server\Logs\Log_Folder_1" & "\" & theDate)
  delFolder.Delete
End If
keepDays=keepDays+1
Loop
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
Tambo
  • 11
  • 1

0 Answers0