Solved

Repeat batch until user presses a key

Posted on 2006-07-19
2
908 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
2 Comments
 
LVL 14

Assisted Solution

by:cwwkie
cwwkie earned 60 total points
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now