Link to home
Start Free TrialLog in
Avatar of sunexchange
sunexchange

asked on

VB Script - Write to Log

Hello
I need help in writing all transactions of my vb script to a log file (success and error)

Can someone help?

Here is my Vb Script:
-----------------------------------------------------------------------------------------------------------------------------------------------

'Delete Log files older than 1 day from vFiler - DB Backups
Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile, objShell
Dim strFolderToSearch, objFSO, objRootFolder, objFolder, colSubfolders, strOutput
Const strMatch = "Log"


'Delete connection if exists
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
On Error Resume Next
objNetwork.RemoveNetworkDrive "L:"

'Set UNC connection to vFiler
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.MapNetworkDrive "L:", "\\10.10.10.1\data\ProdBackups\Database", False, "username", "pwd"


strFolderToSearch = "\\10.10.10.1\data\ProdBackups\Database"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRootFolder = objFSO.GetFolder(strFolderToSearch)
'msgbox objRootFolder

SearchFolders objRootFolder

Wscript.Quit

Sub SearchFolders(objBaseFolder)
   For Each objFolder in objBaseFolder.SubFolders
      'msgbox objFolder.Path
      If InStr(objFolder.Name, strMatch) Then
         
         If DateDiff("d", objFolder.DateCreated, Now) >= 1 Then
            'msgbox objFolder.Path
            objFolder.Delete
            
         Else
            SearchFolders objFolder
         End If
      Else
         SearchFolders objFolder
      End If
   Next
End Sub

On Error Resume Next
objNetwork.RemoveNetworkDrive "L:"
ASKER CERTIFIED SOLUTION
Avatar of ltlbearand3
ltlbearand3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial