"Peter Percival" <***@hotmail.com> wrote
| >
https://stackoverflow.com/questions/8153750/how-to-search-a-string-in-multiple-files-and-return-the-names-of-files-in-powers
|
| Thank you. It so happens that one thing I want to write is a find
| utility that is better than the "Type here to search" box in the lower
| left-hand corner of my screen. (Most anything is going to be better.)
I should think so! Do you know Agent Ransack?
It might be worth a look. I haven't used Windows
search for years. And doesn't it call home now on
Win10?
If you use C you can probably figure out the
landscape here for yourself. For what it's worth:
* You might like javascript better than VBS, insofar
as it's designed to look like C/C++. It has almost
the same functionality in Windows Script Host (WSH).
* WSH can also accomodate installing other languages,
in case you're one of those Perl weirdos. :)
* PowerShell is vast. If you prefer commandline
you should be able to do what you like with that.
* One big difference that's probably worth noting
is that the power of VBS/JS in WSH mainly comes from
COM. Just about any dispatch/dual interface can be
used. And GUI programs can be written with script
and HTML as an HTA. PS, by contrast, seems to
get its power from .Net, with the ability to access
the .Net object model. But I'm somewhat speculating
there. I really don't know much about PS.
* If you look at my scripts page, linked above, the
left side of the index is scripts and the right side
is components that can be used in script. What's
there is probably a good general listing of the kinds
of things you can do with WSH.
I use it to make tools, like the HXStoCHM
converter, and to do little things. I have lots of
VBS scripts on my desktop, to clean up URLs,
fix returns in text files, decode base64, remove
read-only attributes, etc.
An interesting example: Last night I wrote a script
to make a readable webpage from something I
downloaded.
http://www.uceprotect.net/en/index.php?m=7&s=6
I went to the US Congress site to find out whether
any congresspeople I vote for had voted to extend
the FISA spying and warrantless wiretapping law.
(I'm amazed that a majority still support a probably
illegal law that was originally passed shortly after 9/11.)
What I got was a page with limited info. But it turned
out that all of the info was actually in the source code.
There was a line for every house rep:
<recorded-vote><legislator name-id="A000374" sort-field="Abraham"
unaccented-name="Abraham" party="R" state="LA"
role="legislator">Abraham</legislator><vote>Yea</vote></recorded-vote>
I realized it would be easy to write a script to parse
that mess and generate a webpage with a color-coded
listing by party and vote. I wrote the code below, added
the CSS at the top of the XML file, then dropped the XML
file onto the script to generate a readable webpage. That
script may stay on my desktop in case I want to read
future rollcall votes.
'----------------------------------------------
Dim FSO, TS, s1, s2, Arg, A1, i2, Q2
Q2 = Chr(34)
Arg = WScript.Arguments(0)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TS = FSO.OpenTextFile(Arg, 1)
s1 = TS.ReadAll
TS.Close
Set TS = Nothing
A1 = Split(s1, vbCrLf)
For i2 = 0 to UBound(A1)
s2 = A1(i2)
If Left(s2, 15) = "<recorded-vote>" Then
ParseS2 s2
A1(i2) = s2
End If
Next
s1 = Join(A1, vbCrLf)
Set TS = FSO.CreateTextFile(Arg & "2", True)
TS.Write s1
TS.Close
Set TS = Nothing
Set FSO = Nothing
Sub ParseS2(sIn)
Dim Pt1, Pt2, sName, sParty, sVote, sState
Pt1 = InStr(sIn, "field=")
Pt2 = InStr((Pt1 + 7), sIn, Q2)
sName = Mid(sIn, Pt1 + 7, Pt2 - (Pt1 + 7))
Pt1 = InStr(sIn, "party=")
Pt2 = InStr((Pt1 + 7), sIn, Q2)
sParty = Mid(sIn, Pt1 + 7, Pt2 - (Pt1 + 7))
Pt1 = InStr(sIn, "state=")
Pt2 = InStr((Pt1 + 7), sIn, Q2)
sState = Mid(sIn, Pt1 + 7, Pt2 - (Pt1 + 7))
Pt1 = InStr(sIn, "<vote>")
Pt2 = InStr((Pt1 + 6), sIn, Q2)
sVote = Mid(sIn, Pt1 + 6, 1)
If sParty = "R" Then
sIn = "<SPAN CLASS=" & Q2 & "TRed" & Q2 & ">" & sName & " (" & sState &
") </SPAN>"
Else
sIn = "<SPAN CLASS=" & Q2 & "TBlue" & Q2 & ">" & sName & " (" & sState &
") </SPAN>"
End If
If sVote = "Y" Then
sIn = sIn & "<SPAN CLASS=" & Q2 & "TBrown" & Q2 & "> Y
</SPAN><BR>"
Else
sIn = sIn & "<SPAN CLASS=" & Q2 & "TGreen" & Q2 & "> N
</SPAN><BR>"
End If
End Sub