在批处理中使用【if】和【goto】的例子:
@echo off rem This script assumes that REAPER is installed in C:\Program Files\REAPER rem If you have it installed somewhere else, modify this next line to point to the right folder rem OR pass it to the script like: reaper-to-usb.bat "d:\REAPER" set REAPERDIR="C:\Program Files\REAPER" if not '%1'=='' set REAPERDIR=%1 cls :tryagain echo Welcome to the REAPER-TO-USB installation script echo - echo This will copy REAPER and your current REAPER settings to your USB drive. echo - echo Note: you may wish to make sure that you don't have any excess media echo in your REAPER folder or it will be copied as well! echo - echo Enter the drive letter key where your USB drive or removable media is installed echo (i.e. D: or E: or F: etc) set dlet= set /p "dlet=Drive letter (or ENTER to abort): " if /I "%dlet%"=="" goto abort if /I "%dlet%"=="A:" goto suc if /I "%dlet%"=="B:" goto suc if /I "%dlet%"=="C:" goto suc if /I "%dlet%"=="D:" goto suc if /I "%dlet%"=="E:" goto suc if /I "%dlet%"=="F:" goto suc if /I "%dlet%"=="G:" goto suc if /I "%dlet%"=="H:" goto suc if /I "%dlet%"=="I:" goto suc if /I "%dlet%"=="J:" goto suc if /I "%dlet%"=="K:" goto suc if /I "%dlet%"=="L:" goto suc if /I "%dlet%"=="M:" goto suc if /I "%dlet%"=="N:" goto suc if /I "%dlet%"=="O:" goto suc if /I "%dlet%"=="P:" goto suc if /I "%dlet%"=="Q:" goto suc if /I "%dlet%"=="R:" goto suc if /I "%dlet%"=="S:" goto suc if /I "%dlet%"=="T:" goto suc if /I "%dlet%"=="U:" goto suc if /I "%dlet%"=="V:" goto suc if /I "%dlet%"=="W:" goto suc if /I "%dlet%"=="X:" goto suc if /I "%dlet%"=="Y:" goto suc if /I "%dlet%"=="Z:" goto suc cls echo Bad drive letter entered, please try again! goto tryagain :suc mkdir %dlet%\REAPER xcopy /E /Y "%appdata%\reaper\*" %dlet%\REAPER xcopy /E /Y %REAPERDIR%\* %dlet%\REAPER if not exist "%dlet%\reaper\reaper.exe" goto fail cls echo REAPER is now installed on your USB drive in the REAPER folder. echo Just launch REAPER.EXE from your USB drive to use it. Have fun! echo - goto end :abort echo Copy aborted! You can now close this window! echo - goto end :fail echo - echo Copy appears to have failed! goto end :end pause