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
Solved

Repeat batch until user presses a key

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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