Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine two vb scripts.Plz help

Status
Not open for further replies.

dheerajreddy926

Programmer
Apr 15, 2012
10
EU
Hello All,

I am planing for an automation to delete log archives older than 3 days in multiple servers .I have got 2 vb scripts 1) it will read a .txt file where all server paths are kept 2) deletes logs older than 2 days . I want to combine two vb scripts. Please look my scripts
.........................................................
vbs script 1
...........................................................
test2.txt contains path of servers
eg :\\QWMSEAD01\d$\sea77\srvr\LOGARCHIVE
\\QWSEAD02\d$\sea77\srvr\LOGARCHIVE
\\QWMSEAD03\d$\sea77\srvr\LOGARCHIVE




Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\test2.txt", ForReading)

Const ForReading = 1

Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close

For Each strLine in arrFileLines

inputText = strLine

outputArray = Split(inputText)

For Each x in outputArray
WScript.Echo "" & x

Next
Next
--------------------------------------------------
The about script gives me output of input test file .

Vbscript 2
-----------------------------------------------

Const strPath = "\\QWMSEAD01\d$\sea77\srvr\LOGARCHIVE"

Dim objFSO

Set objFSO = CreateObject("Scripting.FileSystemObject")



Call Search (strPath)

WScript.Echo"Done."



Sub Search(str)

Dim objFolder, objSubFolder, objFile

Set objFolder = objFSO.GetFolder(str)

For Each objFile In objFolder.Files

If objFile.DateLastModified < (Now() - 3) Then

objFile.Delete(True)

End If

Next

For Each objSubFolder In objFolder.SubFolders

Search(objSubFolder.Path)

' Files have been deleted, now see if

' the folder is empty.

If (objSubFolder.Files.Count = 0) Then

objSubFolder.Delete True

End If

Next

End Sub
--------------------------------------------------------------
The above script deletes logs at the path given

----------------------------------------------------------

Now i want the output of 1st vb script as input to strPathPlease help me
 
Not tested, so sorry for any errors but...

I simplified the first script here:
Code:
Option Explicit
Dim objFSO, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\test2.txt", ForReading)

Const ForReading = 1

Dim arrFileLines(), strLine
arrFileLines = Split(objFSO.ReadAll, vbCrLf)
For Each strLine in arrFileLines

    Search strLine

Next

WScript.Echo"Done."

Just add your "Search" subroutine after the above code
 
sorry... replace that line with:
arrFileLines = Split([highlight]objFile[/highlight].ReadAll, vbCrLf)
 
Guitarzan,

can you say me the procedure to give the output of that script as input in strPath in 2nd vb script .
 
Delete the () after "Dim arrFileLines(), strLine"
Code:
Dim arrFileLines, strLine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top