English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Im writing a batch file where the user enters the name of his or here document and the program moves the document to a specific folder.
Here is a sample
set /p Name1=What is the name of your first .doc file?
move %Name1%.doc a
echo %Name1% has been moved into new folder

How do you add a catch so that if the user misspells
it prompts the user again for the name of the file?

2007-07-16 08:58:17 · 2 answers · asked by siuboy20 1 in Computers & Internet Other - Computers

2 answers

There are a couple of ways to do this, the easiest would look something like this,

Ask the question, then check to see if the file is there.
If not then inform the user and let them try again.

======
@echo off
:ask
cls
set /p name1=What is the name of your first .doc file?
if exist %name1%.doc goto :MOVE
echo I couldn't find %name1%.doc
echo.
echo Maybe you misspelled it?
echo.
echo Hit Ctrl-C to exit or
pause
goto :ASK
:MOVE
move %Name1%.doc a
echo %Name1% has been moved into new folder

2007-07-18 13:50:59 · answer #1 · answered by Kevin 7 · 6 0

You either load the available answers in an array to validate the characters prior to asking the question or check for the existence of the doc on the spot.

2007-07-16 16:07:41 · answer #2 · answered by Telemon 3 · 0 0

fedest.com, questions and answers