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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read text file and build array

Status
Not open for further replies.
Jul 30, 2004
7
US
Hi Guys,

I need some serious help in getting a VB script together that can:

Part One
open a text file (sites.txt) then read the file line by line excluding the 1st and last line. Then I want to store the values between the quotation marks in an array.

Sites.txt
-------------------------------------------------------------------------------
<Sites Count="10">
<URL=" Owner="EXT\ellynaj.ba" />
<URL=" Owner="DM1\lishmj" SecondaryOwner="DM1\ennisc" />
<URL=" Owner="DM1\ lishmj.dv" />
<URL=" Owner="DM1\treadawaym" SecondaryOwner="DM1\llewellynaj" />
<URL=" Owner="DM1\studc" SecondaryOwner=" DM1\ ellynaj " />
<URL=" Owner="DM1\ studc " SecondaryOwner="DM1\llewellynaj" />
<URL=" Owner="DM1\ ellynaj" SecondaryOwner="DM1\glenn_da" />
<URL=" Owner="DM1\studdsc" SecondaryOwner="DM1\funks" />
<URL=" Owner="DM1\studc" SecondaryOwner="DM1\bosspr" />
<URL=" Owner="DM1\studc" SecondaryOwner="DM1\bosspr" />
</Sites>
-------------------------------------------------------------------------------

Part Two
From the script run a backup program + site name & specify the backup file name using each of the values/ sites stored in the array. The file name should not contain the http:// part of value in the array. I would also like to include a date at the end of the filename. As an example the script should run the following 10 times as there are 10 sites listed in the file.

Backup.exe –s http://t8.abcd.com –f Daily_backup_t8.abcd.com(mmddyyyy).dat
Backup.exe –s http://t8.abcd.com/carrierevaluk –f Daily_backup_t8.abcd.com/carrierevaluk(mmddyyyy).dat

etc. etc

Hopefully this is possible to do via VBscript.

Thanks very much, I appreciate everyone’s suggestions and feedback
 
And what have you so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm not very good with VBscript but this is what I've done thus far. I have a very basic understanding of VBscript so the more help I can get the better.

Code:
Option Explicit
Const ForReading = 1
Const Site_List = "C:\Sites.txt"

Dim SourcePath,SourceFile,DestPath, String
Dim fso, f
Dim arrText()
Dim iUpperBound
Dim Shell
Dim Elem
Dim Site_Backup

Set shell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Site_List, ForReading)

'Used for testing Echo the contents of Site_List
Set f = fso.OpenTextFile(Site_List)
				s = f.ReadAll()
			f.Close()
			n = InStr(1, s, "..")
	MsgBox Right(s,Len(s)-n-1)

' Read the file line by line, and add each line to the array.
iUpperBound = 0
While Not f.AtEndOfStream
   ReDim Preserve arrText(iUpperBound)
   arrText(UBound(arrText)) = f.ReadLine
   iUpperBound = iUpperBound + 1
Wend 

f.Close

' running manually 	
Site_Backup = """C:\Program Files\Common Files\Shared\extensions\BIN\backup.exe"" -s [URL unfurl="true"]http://t8.abcd.com[/URL] –f Daily_backup_t8.abcd.com.dat" 'this line works fine but I need to pull the values from the array instead
Shell.Run Site_Backup

' attempt at running from Array 
For Each site In arrText
	On Error Resume Next
		Shell.Run """C:\Program Files\Common Files\Shared\extensions\BIN\backup.exe"" -s  "& site &" –f Daily_backup_ "& site &".dat"
      	Next
      	
set fso=Nothing
 
Something like this ?
Set f = fso_OpenTextFile(Site_List, ForReading)
While Not f.AtEndOfStream
s = f.ReadLine
If InStr(s, "<URL=") Then
site = Split(s, Chr(34))(1)
Shell.Run """C:\Program Files\Common Files\Shared\extensions\BIN\backup.exe"" -s " & site & " –f Daily_backup_ " & site & ".dat"
End If
Wend

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

I replaced the array code with your code, however I'm not sure what the srcipt is doing, it does not give any errors though Is there a way the I can echo the "site" strings to the screen to see what the completed command would look like? I tried using "msgbox site" however it did not work.

Thanks for help so far it's really appreciated.
 
I tried using "msgbox site" however it did not work
Any error message ?
For debugging purpose you may also consider to add the following line after the ReadLine call:
MsgBox "s='" & s & "'"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top