Solved

Repeat batch until user presses a key

Posted on 2006-07-19
2
913 Views
Last Modified: 2012-08-13
I have the following batch file which searches for a file then copies it into the root folder:

@echo off
setlocal
:START
REM Set variable name filename to prompt result.
set /p fileName=Enter filename?
if "%fileName%"=="" goto :EOF
REM Set expression cnt
set /a cnt=0
REM Search for file in done directory if found, copy
for /f "delims=" %%a in ('dir c:\files\done c:\files\failed /b 2^>NUL ^| findstr /l /c:"%fileName%"') do set /a cnt+=1&set copyName=%%a&echo
%%a

REM If no matching files found, exit.
if /i %cnt% EQU 0 echo No files found matching "%fileName%".

REM If more than one matching file is found, list files and ask user to type in name again.
if /i %cnt% GTR 1 echo More than one file matches "%fileName%". Please be more specific or press CTRL+C to terminate.&goto START

copy "%copyName%" ..

goto :START

What I want to do, is repeat this batch until a key is pressed, for example,

do until (KEY is pressed)
<place batch code here>
repeat

Can this be done in MS-DOS? Is there another alternative?
0
Comment
Question by:horalia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Assisted Solution

by:cwwkie
cwwkie earned 60 total points
ID: 17144229
if you have access to the windows 2000 resouce kit, you can use choice.exe;

    choice /c:QC /T:C,5 press q to quit

This waits 5 second, if the user presses q in that time, errorlevel will be set to 1, otherwise 2

But I don't know if this is what you want?
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 65 total points
ID: 17146404
If you don't mind creating a GETKEY.COM file you could do this:

@echo off

call :CREATEGETKEY

:START

echo Waiting...
getkey

if ERRORLEVEL 1 goto :EOF

goto START

:CREATEGETKEY

if exist GETKEY.COM goto :EOF

(echo a 100)>temp.txt
(echo MOV AH,0B)>>temp.txt
(echo INT 21)>>temp.txt
(echo CMP AL,00)>>temp.txt
(echo JZ 010C)>>temp.txt
(echo MOV AH,07)>>temp.txt
(echo INT 21)>>temp.txt
(echo MOV AH,4C)>>temp.txt
(echo INT 21)>>temp.txt
(echo.)>>temp.txt
(echo r cx)>>temp.txt
(echo 10)>>temp.txt
(echo n GETKEY.COM)>>temp.txt
(echo w)>>temp.txt
(echo q)>>temp.txt

type temp.txt|debug>NUL

del temp.txt >NUL

goto :EOF

Good Luck,
Steve
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question