mistral
Wed Mar 19 14:00:11 CDT 2008
On 16 mar, 00:11, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> mistral wrote:
> >I 'm trying to write vbscript that will do search for specific key
> > word or phrase (will be defined in script) inside PHP files in current
> > folder, include subfolders. Once key word is found, it just opens this
> > file and highlight this word.
> > Any help is appreciated.
>
> I have an example VBScript program that searches for files that contain a
> specified string linked here:
>
>
http://www.rlmueller.net/FindFiles.htm
>
> The recursive subroutine SearchFiles demonstrates how to use the
> FileSystemObject for this. You can specify the file extension, the starting
> folder, the string to search for, and if sub folders are to be searched.
>
> This example outputs the complete file name (with path) of each "hit". It is
> expected that there will be several, perhaps many, file found with the
> specified string. You could modify the script to instead load the files into
> notepad or the Edit command. I don't know how to highlight the string, but
> perhaps you could use code similar to:
>
> ' In the main program create reference to the wshShell object, so we can use
> the Run method.
> Dim objShell
> Set objShell = CreateObject("Wscript.Shell")
>
> ' In Subroutine SearchFiles, replace this statement.
> Wscript.Echo strFile
> ' with this statement.
> Call objShell.Run("%comspec% /c notepad " & strFile, 2, True)
>
> The "True" parameter is needed so the script will wait for you to exit
> Notepad before opening the next file. Otherwise, all of the files will be
> opened at once in separate instances of notepad.
>
> You might be able to use the wshShell object to send keystrokes to the
> notepad app to find the first instance of the string. However, there are
> timing issues I have not resolved. When I tried I could not avoid having the
> script open all files with the string at once. My attempt included the
> following code in the subroutine SearchFiles:
> =======
> Dim blnSuccess
> ' ...
>
> If (InStr(strText, LCase(strSearch)) > 0) Then
> Call objShell.Run("%comspec% /c notepad " & strFile, 2)
> Do Until blnSuccess = True
> blnSuccess = objShell.AppActivate("notepad")
> Wscript.Sleep 1000
> Loop
> objShell.SendKeys "%E"
> Wscript.Sleep 100
> objShell.SendKeys "F"
> Wscript.Sleep 100
> objShell.SendKeys strSearch
> Wscript.Sleep 100
> objShell.SendKeys "{Enter}"
> Wscript.Sleep 100
> intNumber = intNumber + 1
> End If
> ========
> This only worked if just one file was found. Otherwise, I see no way to have
> the script wait for the user to exit notepad before proceeding to the next
> file. If the "True" parameter is used with the Run method, the AppActivate
> and SendKeys methods are not called until after the user exits notepad. One
> solution is to quit after the first hit.
>
> Finally, since writing the script linked above, I have found the command
> findstr. Use can help at a command prompt with:
>
> findstr /?
>
> In my tests it does not appear to be faster than my script (strangely), but
> it has regular expression capabilities. It might be possible to use it in a
> batch file that also opens each file found, but I don't see how you can
> highlight the string found in the file.
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -
http://www.rlmueller.net
----------------
thanks for helpful info. I tried run script from the run prompt in XP
with specified syntax like
cscript FindFiles.vbs <string> <path> <extension> <searchSubs>
but it not worked for me, just show popup Dos window. Probably
vbscript need be in same folder with files where we want to search?
Regards,
mistral