I would be grateful for any help anyone can give with this VBS script. Originally I was trying to come up with a script which would cycle through a folder of HTML files and then extract and list the title text of each HTML file in an output file. By title I mean the text between the <title> and </title> tags within the HTML file. I've managed to do this but then realized that what I really required as well is the ability to amend the title text, save the amended HTML file and output the amended title text to the output file list.
I have managed, after a fashion, to cobble up this rough and ready script which lets me view the text between the title tags [ie <title>text</title>], amend it as necessary and output the amended title text to a list in the outputfile. However, I'm now stuck because I can't figure out how to put the amended text between the "title" tags and save the amended HTML file in the folder while using their original file name.
I am a newbie so my knowledge as yet is still quite limited and I put the script together (don't laugh!) using whatever samples I could find once I figured out what procedures were required. However, I have searched for scripts which will cover this final stage (saving the amended/ unamended HTML files in the folder once the titles/ amended titles have been extracted) but have drawn a blank.
Any help, pointers, script directions would be very welcome
Thank you
AltnNaMara
{code}
Option Explicit
Dim Message, result
Dim Title, Text1, Text2
Dim strTitle
DIM objFSO
DIM strComputer
Dim objWMIService
Dim colFiles
Dim objFile
Dim strContents
Dim strStartText
Dim strEndText
Dim IntStart
Dim IntEnd
Dim intCharacters
Dim strCount
Dim strText
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='J:\VBS-Data_Analysis'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In colFiles
Set objFile = objFSO.OpenTextFile(objFile.Name, ForReading)
strContents = objFile.ReadAll
objFile.Close
strStartText = "<title>"
strEndText = "</title>"
intStart = InStr(strContents, strStartText)
intStart = intStart + Len(strStartText)
intEnd = InStr(strContents, strEndText)
intCharacters = intEnd - intStart
strCount = Mid(strContents, intStart, intCharacters)
wscript.echo strCount
' Define dialog box variables.
Message = "Please Enter New Title"
Title = "WSH user input "
Text1 = "User input canceled"
Text2 = "You entered:" & vbCrLf
' Ready to use the InputBox function
' InputBox(prompt, title, default, xpos, ypos)
' prompt: The text shown in the dialog box
' title: The title of the dialog box
' default: Default value shown in the text box
' xpos/ypos: Upper left position of the dialog box
' If a parameter is omitted, VBScript uses a default value.
result = InputBox(Message, Title, , 100, 100)
' Evaluate the user input.
If result = "" Then ' Canceled by the user
WScript.Echo Text1
Else
WScript.Echo Text2 & result
End If
strCount = Result
strText = strtext & strCount & vbCrLf
Next
Set objFile = objFSO.CreateTextFile("J:\VBS-Data_Analysis\Totals.txt")
objFile.Write strText
objFile.Close
{/code}
<message edited by AltNaMara on Wednesday, January 04, 2012 7:47 AM>