@echo off rem AudManSearch.bat Rev 2.0 2016.08.11, Dick Neubert rem rem Added Multiple Keyword (Boolean AND) search. rem rem Tidied up user interaction for New Search. Note that 'Q' (Quit) used to give option of rem 'New Search' or Quit. Now it means Quit, and N means New Search. rem rem Fixed bug: Used incorrect file path if run from a different drive or partition. rem rem Added flexibility in how to set the help path, depending on user's choice of where to put rem the .bat file. The options are selected by removing 'rem 's in the .bat file. rem See options under "*IMPORTANT*" for these. rem rem The original method of hard-coding the path is still there for those who insist on saving rem the .bat file on the desktop (but it can be put anywhere). I added 'if not defined' before rem the 'set' command to allow the environment variable to be pre-initialized. rem AudManSearch.bat Rev 1.1 2016.08.05 rem (eliminated temp file, added rotating selection and New Search), by Dick Neubert. rem This is a batch file for Windows to search the Audacity manual for a given word or phrase. rem It returns a list of the subjects (files) in which the phrase occurs. User can select them rem individually for display in the default html viewer. I haven't figured out how to open multiple rem files simultaneously in browser tabs but Mozilla, Chrome and IE, at least, will add tabs if the rem user selects additional files for display (might depend on browser settings). If browser is not rem already open, control may not return to this script after launching it until browser is closed. rem Regular Expression and Boolean OR & AND NOT searches are not supported by this script, rem but Regular Expression could be added. I think GREP is a better program for that than FINDSTR, rem but I used FINDSTR because it comes with Windows whereas GREP would have to be downloaded. rem This file may be saved on the Desktop, or saved elsewhere and a shortcut sent to the Desktop. rem Double-click the icon to run the script, and enter the search phrases/keywords when prompted. rem If you just hit 'Enter' in response to the prompt, the script will display instructions. rem *IMPORTANT* rem Change the text after '=' in the following 'set' command to the pathname of your help folder: if not defined AudacityHelp set "AudacityHelp=C:\Program Files (x86)\Audacity 2-1-2\help" rem Alternatively (option 1), you can initialize an environment variable, AudacityHelp, to this path. rem This requires some competence in editing system files and is beyond the scope of these instructions. rem If the environment variable already exists, the 'if not defined' above will prevent changing it. rem Alternatively (option 2), if you run this script from a shortcut, you can put the .bat file rem anywhere on any drive/partition and send the shortcut to the desktop. Edit the shortcut to set rem "start in" (in Properties) to the drive:\path of the Audacity help folder as above and remove rem the 'rem ' from the following line: rem set "AudacityHelp=." rem Alternatively, (option 3) you can save this .bat file in your Audacity folder with rem the help folder (not IN the help folder), and remove the 'rem ' from the following line: rem set "AudacityHelp=%~dp0\help" rem This lets you double-click on the file or on a shortcut. The shortcut will by default have rem "start in" set to the Audacity folder rather than the help folder which it contains. With rem this option, it makes no difference. Assuming your Audacity folder is in Program Files or rem Program Files (x86), you have to provide Administrator permission to save the .bat file there, rem and you can't edit it there so remove the 'rem ' before copying. setlocal enableExtensions enableDelayedExpansion cd /d %AudacityHelp%\manual\man if errorlevel 1 goto :patherr :gettok rem prompt user for search string: echo. echo Enclose in quotes if searching for a phrase; Just 'Enter' for instructions. echo. set search= set /p search= Search for: echo. if defined search goto :search rem Empty line, show instructions: echo This batch script searches your Audacity manual for a given word or phrase. echo It will do multiple keyword searches but not "regular expression" searches. echo Phrases must be enclosed in quotes, o/w they are taken as keyword lists. echo If multiple keywords/phrases are given, only results matching all of them echo are returned. echo. echo A list of files containing the search string(s) will be displayed. You can echo either go to those subjects in Audacity Help or select them hence for display echo in your default HTML viewer (usually a browser). If browser is already open, echo you should be able to select other matches for display. If it was not already echo open, control may not return to this script until you close the browser. echo. echo When matches are found, you are prompted for each one: echo. echo "Display/[skip]/New search/Quit" echo. echo Only the 1st letter of your response counts, and 'skip' is the default. After echo the end of the list, it repeats from the top. echo Rev 2.0 2016.08.11 by DickN. echo. choice /C SQ /N /M "Search or Quit?" if %errorlevel%==1 goto :gettok goto :finis :search rem Tried to do this nested 'for' using /F switch in outer 'for', but it didn't work. rem Outer 'for' executed only 1 pass regardless of number of tokens. See :rotate below. rem Seems to be an issue with using the extension in outer 'for' with nested 'for'. rem initialize file list (mfiles = match files, sfiles = search files) set sfiles= for %%f in (*.html) do set "sfiles=!sfiles! %%f" if not defined sfiles goto :patherr rem @echo on for %%k in (%search%) do ( set mfiles= for /F "usebackq" %%m in (`findstr /I /M /C:"%%~k" !sfiles!`) do set "mfiles=!mfiles! %%m" if not defined mfiles goto :nomatch set "sfiles=!mfiles!" ) if defined mfiles goto :show :nomatch echo No matches found. goto :gettok :show @echo. @echo Matches: @echo. rem Display file list: for %%f in (%mfiles%) do @echo %%f rem Let user pick one at a time for display (I haven't figured out how to open a set in tabs): set repl=q :rotate rem Tried to do this with a nested 'for' but it didn't work. Had 'for /L %%z in (0,0,0) do (the 'for' below)'. rem The 'if' in the inner 'for' worked only with 'if expr exit'. 'if expr goto symbol' hung. @echo. for %%f in (%mfiles%) do ((call :select %%f) & (if /i !repl!==Q goto :finis) & (if /i !repl!==N goto :gettok)) goto :rotate rem subroutine to display file contents via default viewer :select set repl=s rem Get user's selection for action with this file: @set /p repl= %1 (Display/[skip]/New search/Quit)? rem Keep only the 1st character of reply for tests: set repl=%repl:~0,1% rem Issuing filename.html as a command opens it in the default html viewer: if /i %repl%==D call "%~1" rem return from subroutine goto :eof :patherr echo. echo Invalid path for help folder. echo %~nx0 must be edited to insert the correct pathname echo or enable getting the path by other means. echo Instructions for this are given in the file (see echo "*IMPORTANT*"). echo. echo Note: If you're using Windows XP or later, you can echo right-click this file or icon and select 'Edit', or echo drag the %~nx0 file to Notepad. :finis set files= set sfiles= set search= echo. echo. Press any key to close window. pause >nul: