Solved

Repeat batch until user presses a key

Posted on 2006-07-19
2
912 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Script to copy every 7th file 10 61
DOSBox Keyboard 3 103
robocopy 6 69
How to remove unwanted words? 34 64
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…

679 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