Reputation: 189
Problem
I have 2 folders (each contain one file), and I am trying to copy the files from one to the other. The CHOICE command I have written works properly; however, after an answer is chosen the program closes immediately (no matter what choice is selected). A line was displayed "1 was unexpected at this time" as it was closing.
My Code
ECHO. & CHOICE /C:123 /N /M "Copy? (1. Copy 2. Exit 3. No Choice)" & ECHO.
::assigns choice values for user
IF /i %errorlevel1% EQU 1 GOTO copy
IF /i %errorlevel2% EQU 2 GOTO end
IF /i %errorlevel3% EQU 3 GOTO no_choice
::based on selection, redirects to logic
:copy
ECHO.
ECHO.
ECHO You chose to COPY the files... Hit any key to START or ctrl-z to CANCEL.
PAUSE > NUL
SET src_folder=d:\batch
SET dst_folder=d:\newBatch
FOR /F "tokens=*" %%i in (batch.txt) DO (
xcopy /S/E/U "%src_folder%\%%i" "%dst_folder%")
GOTO end
::offers cancel; if continue, copies files from batch to newBatch
:end
EXIT
::ends program
:no_choice
ECHO No action has been performed...
PAUSE
EXIT
::print message; then ends program
Research
I have searched all over the web, as well as some of this site's posts, and it helped me construe what I currently have here. The most recent Stack Overflow post I reviewed over this topic was found here (Error: 1 was unexpected at this time). I implemented the "/i" fix that was mentioned in this post, but the individual asking the question was simply validating ECHO statements rather than CHOICE.
Question
Thanks!
Upvotes: 0
Views: 120
Reputation: 67256
You made a mistake in the name of ERRORLEVEL variable.
IF %errorlevel% EQU 1 GOTO copy
IF %errorlevel% EQU 2 GOTO end
IF %errorlevel% EQU 3 GOTO no_choice
The /i
option is not necessary in this case...
Upvotes: 1