Script to find and open file. Help.

June 26, 2008 at 09:41:35
Specs: DOS, N/A

Hello All.

I’m at the end of my wit here and I was wondering if any one could help me out.

My job requires me to monitor an application for several issues that may arise. For every issue there is a corresponding guide/manual on how to deal with the issue. All the guides are stored in one central location. So I would typical browse the central location and find the correct manual.

Originally the application itself was designed to automatically open the corresponding guide once the issue alert was received. However, for what ever reason it never worked and no one seemed to be motivated to make it work.


Well, I thought to my self here is a perfect opportunity to get organizational wide recognition. If I can get this to work, all will echo my name though out our organization. My name will be synonymous with greatness. However, my efforts have proven to be bitter sweet and I fear people will not recognize me as the intellectual dynamo I truly am.


So far I’ve been able to reduce the time it takes me to find the guides/manuals by running these two commands in a DOS screen:

echo off
FOR %G IN (*.xls) do (findstr /M "issue name" "%G")

Once the answer is returned I run copy the guide name into the following command and run it.

Start excel "guide name"


If at all possible I would like to just automate the entire process so that I just have to enter the issue name. I’ve come up with the script below, but am having problems coding the batch file to open the corresponding guide. Can any one help?


REM section (1) used to prompt for job name.

@Echo Off
:LOOP
ClS
Echo.
Set /P Job=Enter the issue name^>
Echo.
Set /P Answ=..Enter Y/y to proceed^>
If /I not "%Answ%"=="Y" GoTo :LOOP


Echo...Just a moment while I find a guide for the job %job%

REM Section (2) used to find the guide.

f:
echo off
Rem the double percent sighn i.e "%%" are only used in batch files. other wise it would be a single percent sign.


FOR %%G IN (*.xls) do (findstr /M %job% "%%G")


Rem this line will later be used to to automaticallys start the support guide.
Rem start excel "TSFS EBOInsurance Tidal Monitoring Worksheet Feb-11-08 MS.xls"


REM this continues where the section (1) left off.
Set Strg=
Set File=
Set Answ=
::End_Of-Batch


See More: Script to find and open file. Help.

Report •


#1
June 26, 2008 at 13:05:11

Stated you are running under a Windows system (probably Win XP/2K) where there is no DOS but NT system console where you issue your batches/commands, here a first aid to open the guide(s) related to the "issue name" by just one shot

:: ALERT.BAT Usage: ALERT issue name
@echo off
for /F "tokens=* delims=" %%j in ('findstr /M "%*" *.xls') do (
start "" excel "%%~fj"
)
:: End_Of_Batch

Just type the issue name after the batch name without embedding quotes.

If the application to be monitored can be forced to redirect the warnings the whole process can be automated.


Report •

#2
June 26, 2008 at 14:22:02

For now I think it safe to assume that they wont modify the application.

Ill try adding this code to my code to see if it works. I will let you know what happens.


Report •

#3
June 26, 2008 at 14:29:22

err I was retro-fit your code. However, im not sure I understand what its doing.

could you shed a bit of light?
Thank you soo much in advance.


Report •

Related Solutions

#4
June 27, 2008 at 01:56:00

The code I posted is just an improved version of what you showed in the original message.

For /F parses the output of the command <Findstr /M "%*" *.xls> where %* is what you type as parameter for the batch ALERT. E.g. if you issue

alert time out on port 457

the batch looks for "time out on port 457" inside all .xls files in the current directory and then opens the guides found (%%~fj). You want to replace *.xls with the full path of folder holding your guides (e.g. "D:\Guides Library\*.xls" - don't miss quotes if there are embedded blanks).

The For /F is a powerful NT batch statement to set up compound commands using the output of thr first one as the input for the second. It's the root for whatever automation process as it allows a command is driven by another one.

About my note on redirection of the native application warning, it may be a simple command line replacement by no way involving the application internal. More info on this is however needed.


Report •

#5
July 19, 2008 at 21:31:26

Dynamo here.

I never replied. I just wanted you to know. It took a while for me to figure out how to get this working. With your help this program is working perfectly.

Thanks a million, I really appreciate it.


Report •

#6
September 10, 2008 at 12:46:19

Oh, my god. my original project was soo good that I have gained attention from other departments. They now want me to improve my original batch file.

What they want is for my original script to find an item on an excel spread sheet. Once found they want the script to match that item to a specific condition then display it.

Currently we have several excel spread sheets that has this information. basically there are several items with specific conditions and specific actions to be taken for each condition. I was content with just finding the proper spread sheet... The stakes have been risen to print only the specific item,condition,action to be taken.....

please help. and thanks in advance.

Below is a copy of the script with company details rip out.

REM section (1) used to prompt for item name.

@Echo Off
:LOOP
ClS
Echo.
Set /P Job=Enter the item name^>
Echo.
Set /P Answ=..Enter Y/y to proceed^>
If /I not "%Answ%"=="Y" GoTo :LOOP


Echo...Just a moment while I find an excel spread sheet for the item %job%


REM Map F drive.

NET USE /P:no F: \\"share name here"
F:
cd "dirctory name here"

REM Section (2) used to find the support guide.

f:
echo off
Rem the double percent sighn i.e "%%" are only used in batch files. other wise it would be a single percent sign.

for /F "tokens=* delims=" %%j in ('findstr /M "%Job%" *.xls') do (
start "" excel "%%~fj"
)
:: End_Of_Batch



REM this continues where the section (1) left off.
Set Strg=
Set File=
Set Answ=
::End_Of-Batch

exit


Report •


Ask Question