Click to See Complete Forum and Search --> : DOS/Batch File


lordofdavipers
01-13-2012, 05:00 PM
It's been a long time since I've been here but I still love this place because everyone is so very helpful and I hope, once again, I can get the great assistance as before.

I have not always programmed with batch files but since starting at my new I.T. job I now use them somewhat extensively to automate or make some tasks I do easier. I'm now on my fourth one and have run into a road-block that I hope you guys can help me out with.

Short of the long, we have an internal knowledge base at work of which we search by keyword to find the article(s) we desire. I have written a script, basically for testing my skills, to search the kb by way of the batch file. However, I ran into one stump that I didn't catch originally...the KB uses plus (+) signs in place of spaces. I cannot find for the life of me how to convert spaces to + symbols. I have read mixed reviews that batch files cannot process/parse this and you must use a more powerful programming language such as VB, C++ or something of the like. I'm not quite skilled in those and don't necessarily need this that much.

Although I wrote a nice book above, my question is simply this. Is it true that you cannot perform the above function of converting spaces to + symbols (or any other desired character) or is it possible? If it is, could someone please look at the following code and see if it's possible or where I went wrong (as you'll see my REM statements).

I greatly appreciate any and all assistance!

Code As Follows:


@echo off

TITLE .::KB Quick Search - V. 0.0.1::.

rem CREATE DATE: Wednesday, January 11, 2012, 5:47:17 PM

rem VERSION 0.0.1 (0.0.1 is alpha/beta build. No detailed documentation.)



REM TO DO: CREATE ABILTITY TO CONVERT A SPACE TO A + SYMBOL.



rem THIS FILE IS CREATED AND OWNED BY ANDREW COODY. DO NOT RIP OFF. SEE HELP FILE.



rem http://aaronskb.aaronrents.com/novo/dosearch.asp?words=KEYWORD







rem cls

rem echo.

rem echo.

rem echo.

rem echo. KB Quick Search is designed to load a KB search directly from the command line to the IE/FF search window.

rem echo.

rem echo.

rem echo.

rem pause.



:new



:step0

cls

:step00

rem Destoys value in case values were set.

set "kb="

echo.

echo.

echo.

echo.

echo.

echo.

echo.

echo.

echo.

echo.Type "q" to quit.

echo.Temporarily, please input a "+" instead of a space. (VIP+Void)

echo.

set /p "kb=Please enter your KB Quick Search: "

rem NULL VALUE AUDIT



rem if kb ==" " (echo. %kb%"+" && goto :step0end)



rem DOES NOT WORK if kb=="%kb&& %" ren "%kb&& %" "%kb&&+%"





if not defined kb (cls && echo. && echo. && echo. No blank values allowed. Please enter a search term or type "q" to quit. && echo. && echo. && echo. && goto :step00)







if %kb% ==q (goto :quit) ELSE (goto :step0a)

:step0a



:step0end







start http://aaronskb.aaronrents.com/novo/dosearch.asp?words=%kb%



cls

echo.

echo.

echo.

echo.

echo.

echo.

echo.

echo.

echo.

echo.

echo.

echo. Program will close automatically. Please wait.

ping -n 5 127.0.0.1>nul


:quit

Andrew

bionoid
01-13-2012, 05:15 PM
I've recently stumbled apon some replacement features of a batch file that I will share:

Go.Bat
@Echo Off
Cls

SET Search=%1
SET Search=%Search: =+%
SET Search=%Search:"=%

Echo %Search%

As a usage example:

Go "This is a test"

You end up with:

This+is+a+test

If you want to retain the quotes then remove the last SET.
I think this works on XP as well, I haven't tried any OS older than that.

Hope that helps.

lordofdavipers
01-13-2012, 05:18 PM
I will try that in a few and see if it works. I greatly appreciate your steadfast response!

Andrew

lordofdavipers
01-13-2012, 05:23 PM
Forgive me, do you mind explaining what the %1 does?

bionoid
01-13-2012, 05:27 PM
%1 would be the first parameter following the Batch file command eg: "This is a test"... %0 would be the actual command etc.
Because I wrapped everything in quotes it all ends up as %1. If I didn't you would get values in %1 %2 %3 %4 for each word.

I couldn't get the replacement part of things working directly on that variable so I assigned it to %Search% first.

I assumed that a batch file that searches things would need outside influence.

bionoid
01-13-2012, 06:00 PM
After reading your initial batch file, I see that you're using a prompt.
That would make the code look more like:

Go.Bat
@Echo Off
Cls

SET /P kb=Please enter your KB Quick Search:
SET kb=%kb: =+%

Echo.
Echo %kb%

lordofdavipers
01-13-2012, 06:18 PM
That did it!

You're wonderful. Thank you very kindly for your assistance!

Andrew

bionoid
01-13-2012, 06:20 PM
Great :)

You're welcome.