I have a batch file to help clients do automated backup of their files, however it's not editing friendly to them, so I plan to make the clients input a letter for the destination drive of their backup.
The problem is, I do not know how to limit their input to only one characters and only a-z
I have read this resource > Batch File input validation - Make sure user entered an integer . But still can't figure out any solution
The question is, do we really can limit the input length and the validation thing? are there any reference can use on this matter?
here is my code
: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