Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Repeat batch until user presses a key

Posted on 2006-07-19
2
Medium Priority
?
924 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 240 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 260 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

773 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