Link to home
Start Free TrialLog in
Avatar of Lia Nungaray
Lia NungarayFlag for United States of America

asked on

Repeat batch until user presses a key

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?
SOLUTION
Avatar of cwwkie
cwwkie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial