我有一個批處理文件來幫助客戶端自動備份他們的文件,但是它不會對他們編輯友好,所以我打算讓客戶端爲其備份的目標驅動器輸入一個字母。批處理文件輸入驗證和限制
的問題是,我不知道如何將他們的輸入限制在只有一個字符,只有A-Z
我已閱讀本資源> Batch File input validation - Make sure user entered an integer。但仍然無法找出任何解決方案
問題是,我們真的可以限制輸入長度和驗證的東西嗎?有沒有任何參考資料可以用於此事?
這裏是我的代碼
:init
@echo off
color 02
REM -- set vars
set tgl=%DATE:~0,2%
set bln=%DATE:~-7,2%
set thn=%DATE:~-4,4%
set jam=%TIME:~0,2%
if "%time:~0,1%"==" " set jam=0%TIME:~1,1%
set menit=%TIME:~3,2%
set detik=%TIME:~6,2%
echo Under which drive will you save the backup? (one letter only, a-z)
set /p drive=
pause
cls
:stopsvc
net stop svc01
cls
echo stop service [OK]
echo copy files [ ]
echo start service [ ]
echo archiving [ ]
echo.
REM -- start backup
echo.
:copy
echo copying ...
xcopy /e /y c:\docs %drive%:\data\docs\
cls
echo stop service [OK]
echo copy files [OK]
echo start service [ ]
echo archiving [ ]
echo.
echo.
:startsvc
echo starting MySQL service...
net start svc01
if errorlevel = 1 goto svcfail
echo.
echo done
cls
echo stop service [OK]
echo copy files [OK]
echo start service [OK]
echo archiving [ ]
echo.
echo.
echo backup successfully created
echo now archiving ...
echo.
:archive
cd "%drive%:\data"
ren "docs" "BACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%"
echo archiving - OK
cls
echo stop service [OK] > "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo copy files [OK] >> "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo start service [OK] >> "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo archiving [OK] >> "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo.
echo.
echo buhbye
echo copyright(c) [SC] 2010-2011
pause
goto eof
:svcfail
echo cannot start svc01 service > "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo start it manually through services.msc >> "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo.
echo.
echo stop service [OK]
echo copy files [OK]
echo start service [FAIL]
echo archiving [ ]
pause
goto archive1
:archive1
cd "%drive%:\data"
ren "docs" "BACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%"
echo archiving - OK
cls
echo stop service [OK] >> "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo copy files [OK] >> "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo start service [FAIL] >> "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo archiving [OK] >> "logBACKUP-[%jam%.%menit%]-%tgl%-%bln%-%thn%.txt"
echo.
echo.
echo all done~!
pause
goto eof
:eof
exit
您可以使用choise獲取只有一個字符(Vista,Win7) – jeb
但這將是約。 23選擇,但我會嘗試 – skeith