"McKirahan" <News@xxxxxx> wrote in message
news:scidnd3zCclfOcLVnZ2dnUVZ_rfinZ2d@xxxxxx
> > "Daz" <darren.blackley@xxxxxx> wrote in message > news:2e7038f4-119c-49a9-885f-> bfa16d8e12f2@xxxxxx...
[snip]
I don't have answers to all of my questions but here's something.
Will this help? Watch for word-wrap.
Save it as "SVCPack.hta" then create "SVCPack.txt" which contains a list
of files (with their full path; one per line) that you may want to edit.
For example, "C:\Temp\SVCPack.inf".
To run it, doubleclick on "SVCPack.hta" (in Windows Explorer),
select a file by clicking on its name and its contents will be displayed
in the text area. You can now manually edit the file or enter one or more
lines of text which you can insert at the cursor location. After making
your changes click "Replace" to backup the file then replace it.
<html>
<head>
<title>SVCPack.hta</title>
<HTA:Application
ID = "HTA"
ApplicationName = "SVCPack"
Border = "thin"
BorderStyle = "normal"
Caption = "yes"
ContextMenu="yes"
Icon = ""
InnerBorder="no"
MaximizeButton = "yes"
MinimizeButton = "yes"
Navigable="yes"
Scroll="yes"
SrollFlat="no"
Selection="yes"
ShowInTaskBar = "yes"
SingleInstance = "yes"
SysMenu = "yes"
Version = "1.0"
WindowState = "maximize"
<script type="text/vbscript">
Option Explicit
'****
'* This HTA (HTML Application) does the following:
'* 1) Reads "cTXT" which contains a list of (path+) filenames
'* and builds a dropdown list to allow selection.
'* 2) Reads the selected file into a textarea;
'* (".inf" extensions builds a dropdown list of Sections).
'* 3) Changes may be made directly to the file or lines
'* may entered in a textarea for inserting into multiple files.
'* 4) If the file has been changed then it may be saved which
'* replaces the original file after it is "backed up" first by
'* copying it with a timestamp extension: ".yyyymmddhhnnss".
'****
'*
'* Declare Constants
'*
Const cHTA = "SVCPack.hta"
Const cTXT = "SVCPack.txt"
'*
'* Declare Globals
'*
Dim sDIR
sDIR = CreateObject("WScript.Shell").CurrentDirectory + "\"
Dim sERR
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim sINF
Dim dNOW
Dim sNOW ' yyyymmddhhnnss
Dim aOTF
Dim iOTF
Dim oOTF
Dim sOTF
Dim iOPT
Dim sOPT
Dim sSAV
Dim sTMP
Sub File_List()
'****
'* Read file.
'****
'*
'* Test
'*
If Not oFSO.FileExists(sDIR & cTXT) Then
sERR = "<b>" & cTXT & "</b> does not exist!"
document.getElementById("Note").innerHTML = sERR
Exit Sub
End If
'*
'* Read
'*
Set oOTF = oFSO.OpenTextFile(sDIR & cTXT,1)
sOTF = oOTF.ReadAll
Set oOTF = Nothing
'*
'* List
'*
iOPT = 1
sOPT = "<option value=''>" & vbCrLf
aOTF = Split(sOTF,vbCrLf)
For iOTF = 0 To UBound(aOTF)
sOTF = Trim(aOTF(iOTF))
If LCase(Left(sOTF,1)) >= "a" _
And LCase(Left(sOTF,1)) <= "z" _
And Mid(sOTF,2,2) = ":\" Then
If oFSO.FileExists(sOTF) Then
iOPT = iOPT + 1
sOPT = sOPT & "<option value='" & sOTF & "'>" & sOTF &
vbCrLf
Else
Alert(sOTF & " file does not exist!")
End If
End If
Next
sOPT = sOPT & "</select>" & vbCrLf
sOPT = "<select id='Pick1' onchange='File_Read()' size='" & iOPT & "'>"
& sOPT & vbCrLf
'*
document.getElementById("List").innerHTML = sOPT
End Sub
Sub File_Read()
'****
'* Read file.
'****
document.getElementById("Note").innerHTML = ""
document.getElementById("Sect").innerHTML = ""
document.getElementById("Data").Value = ""
sINF = document.getElementById("Pick1").Value
If sINF = "" Then Exit Sub
'*
'* Test
'*
If Not oFSO.FileExists(sINF) Then
sERR = "<b>" & sINF & "</b> does not exist!"
document.getElementById("Note").innerHTML = sERR
Exit Sub
End If
'*
'* Read
'*
Set oOTF = oFSO.OpenTextFile(sINF,1)
sOTF = oOTF.ReadAll
Set oOTF = Nothing
document.getElementById("Data").Value = sOTF
sSAV = sOTF
'*
'* INF Sections
'*
If Right(LCase(sINF),4) <> ".inf" Then Exit Sub
iOPT = 0
sOPT = ""
aOTF = Split(sOTF,vbCrLf)
For iOTF = 0 To UBound(aOTF)
sOTF = Trim(aOTF(iOTF))
If Left(sOTF,1) = "[" _
And Right(sOTF,1) = "]" Then
iOPT = iOPT + 1
sOPT = sOPT & "<option value='" & sOTF & "'>" & sOTF & vbCrLf
End If
Next
'*
sOPT = sOPT & "</select>" & vbCrLf
sOPT = "<select size='" & iOPT & "'>" & sOPT & vbCrLf
sOPT = "<b>Sections:</b><br>" & vbCrLf & sOPT & vbCrLf
document.getElementById("Sect").innerHTML = sOPT
End Sub
Sub File_Position()
'****
'* Inserting at the cursor using JavaScript
'*
http://alexking.org/blog/2003/06/02/...ing-javascript
/
'****
sTMP = document.getElementById("Entry").Value
If sTMP = "" Then Exit Sub
If MsgBox("Insert text at cursor position?",vbQuestion+vbYesNo,cHTA) =
vbYes Then
document.getElementById("Data").focus()
document.selection.createRange().text = sTMP
End If
End Sub
Sub File_Replace()
'****
'* Copy old file and Write new file.
'****
dNOW = Now
sNOW = Year(dNOW) _
& (10^8 * Month(dNOW)) _
+ (10^6 * Day(dNOW)) _
+ (10^4 * Hour(dNOW)) _
+ (10^2 * Minute(dNOW)) _
+ (10^0 * Second(dNOW))
sOTF = document.getElementById("Data").Value
'*
'* Test
'*
If sINF = "" Then
sERR = "<b>No file selected!</b>"
document.getElementById("Note").innerHTML = sERR
Exit Sub
ElseIf sOTF = "" Then
sERR = "<b>" & sINF & "</b> is empty!"
document.getElementById("Note").innerHTML = sERR
Exit Sub
ElseIf sSAV = sOTF Then
sERR = "<b>" & sINF & "</b> not changed!"
document.getElementById("Note").innerHTML = sERR
Exit Sub
End If
'*
'* Copy
'*
oFSO.CopyFile sINF, sINF & "." & sNOW
'*
'* Write
'*
Set oOTF = oFSO.OpenTextFile(sINF,2,true)
oOTF.Write(sOTF)
Set oOTF = Nothing
End Sub
Sub Window_Onload()
'****
'* List files.
'****
Call File_List()
End Sub
</script>
<style type="text/css">
body,td,th { font-family:Arial; font-size:80% }
..butt { background-color:white; width:80px; height:22px }
..text { font-family:Courier; font-size:10pt }
..yell { background-color:yellow }
</style>
</head>
<body>
<table border="0" width="90%">
<tr valign="top">
<td>
<b>Select a file:</b>
<br>
<span id="List"></span>
<br><br>
<span class="yell" id="Note"></span>
<br><br>
<b>Text to be inserted at cursor position:</b>
<br>
<textarea class="text" id="Entry" cols="30" rows="10"
wrap="virtual"></textarea>
<br><br>
<input type="button" class="butt" value="Insert"
onclick="File_Position()">
<input type="button" class="butt" value="Replace"
onclick="File_Replace()">
<input type="button" class="butt" value="Exit" onClick="Self.Close()">
<br><br>
<span id="Sect"></span>
</td>
<td>
<textarea class="text" id="Data" cols="72" rows="50"
wrap="virtual"></textarea>
</td>
</tr>
</table>
</body>
</html>