Gene E. Bloch said:
Yes.
But the command window that pops up will go away after you make a
choice...unless you run the backup program using "cmd /k" or "cmd
/c".
Note that the first line of the batch file above needs to be
changed:
CHOICE /C FGHIN /N /M "Backup to drive F:, G:, H:, I: (or N for
None)?"
The /M and the quotes are required; the colon after /C is ok,
though.
Here's a slightly prettier (more informative) version of the batch
file:
<Bat File>
@echo off
CHOICE /C FGHIN /N /m "Backup to drive F:, G:, H:, I: (or N for
None)?"
IF ERRORLEVEL 1 SET DRIVE=F:
IF ERRORLEVEL 2 SET DRIVE=G:
IF ERRORLEVEL 3 SET DRIVE=H:
IF ERRORLEVEL 4 SET DRIVE=I:
if errorlevel 5 (
echo No backup drive chosen
echo/
goto :EOF
)
ECHO Backing up to %DRIVE%
echo/
REM Put your code here, as in
cmd /k backup_code
</Bat File>
Weirdly enough, if you save this as a cmd file, the errorlevel tests
above have to be in the other order, i.e., test for 5 first, then
4,...
That struck me as so unlikely that I spent too much time setting up
a
file where I could control the test order from the command line, and
sure enough, the batch file has to test in one order and the command
file in the other.
BTW, everything in that file is case-insensitive, so most of my
changes
are in lower case, for visibility.
You shouldn't have to reverse the order, unless you change from SET
DRIVE=F: to something like GOTO DRIVE_F. The reason you would need to
for the GOTO version is that errorlevel tests are not really an equal
to, rather they are greater than or equal to, so a test for
ERRORLEVEL=0 is always true (unless there is some way to generate a
negative errorlevel, that is) and ERRORLEVEL=1 is true for any
errorlevel greater than 0, etc.
The above, of course, is my understanding of how it works and my
experience with batch files under DOS, XP and Vista, and is not based
on actual testing with a CMD file under Windows 7, so I'll be happy to
be proven wrong if in fact my understanding is inaccurate.
BTW, a great resource for CMD and batch scripting is
alt.msdos.batch.nt (.nt is taken to mean any Windows version from NT
and following, so would include Vista and Win7, btw). If the guys
posting in there can't do it, it can't be done!
--
Zaphod
Arthur Dent, speaking to Trillian about Zaphod:
"So, two heads is what does it for a girl?"
"...Anything else he's got two of?"