beberapa contoh batch file lagi

kill.bat (short):

Displays a list of files to be deleted, and prompts for confirmation.

@echo off
dir /w %1 | find /v "Volume " | find /v "file(s)" | find /v "dir(s)"
choice /c:ny Do you really want to delete these
rem if errorlevel 2 del %1
if errorlevel 2 echo (I would have deleted them)

kill.bat (long):


@echo off
echo Here are the files to be deleted:>tmp
set dirc1=%dircmd%
set dircmd=
dir /a-d %1 | find /v " Volume " | find /v "dir(s)" | find /v "Directory of" | find " " >> tmp
set dircmd=%dirc1%
set dirc1=
type tmp|more
choice Are you sure 
if errorlevel 2 goto DoNotDel
if errorlevel 1 goto KillThem
rem The following is just in case
rem "choice" does something unexpected ...
echo Something else happened!
goto end

:KillThem
rem Here's where we would put the "del" command
echo They are gone.
goto end

:DoNotDel
echo They are still there.
:end

number.bat:

Given a two digit number, translates it into words. For example, "number 1 3" produces "thirteen", and "number 4 1" produces "forty one".

@echo off
if _%2==_ goto error
if not _%3==_ goto error
set tens=
set ones=
for %%v in (0 1) do  if %1==%%v goto First%%v
if %1==2 set tens=twenty 
if %1==3 set tens=thirty 
if %1==4 set tens=forty 
if %1==5 set tens=fifty 
if %1==6 set tens=sixty 
if %1==7 set tens=seventy 
if %1==8 set tens=eighty 
if %1==9 set tens=ninety 
if not _%tens%==_ goto ones

:error
echo Please enter exactly 2 digits.
goto end

:First1
if %2==0 set tens=ten
if %2==1 set tens=eleven
if %2==2 set tens=twelve
if %2==3 set tens=thirteen
if %2==4 set tens=fourteen
if %2==5 set tens=fifteen
if %2==6 set tens=sixteen
if %2==7 set tens=seventeen
if %2==8 set tens=eighteen
if %2==9 set tens=nineteen
goto done

:First0
set ones=zero
if %2==0 goto done
set ones=

:ones
if %2==0 set ones= 
if %2==1 set ones=one
if %2==2 set ones=two
if %2==3 set ones=three
if %2==4 set ones=four
if %2==5 set ones=five
if %2==6 set ones=six
if %2==7 set ones=seven
if %2==8 set ones=eight
if %2==9 set ones=nine
if _%ones%_==__ goto error

:done
if _%tens%%ones==_ goto error
echo %tens%%ones%
set tens=
set ones=
:end

zipcode.bat:

This batch file takes a 5 or 9 digit ZIP code and prints out its "bar code."

@echo off
rem Fewer than 5 digits?
if _%5==_ goto BadInput
if _%6==_ goto FiveDigits
rem More than 5, but fewer than 9 digits?
if _%9==_ goto BadInput

:FiveDigits
set digits=
set ziperror=NO
rem If there are only five digits, %6--%9 are blank
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do call onedigit %%v
rem ziperror set to YES if any characters were not digits.
if %ziperror%==YES goto BadInput
rem Following two lines check to see if more than 9 numbers were given
shift
if not _%9==_ goto BadInput

echo %digits%
goto Finished

:BadInput
echo You must enter either 5 or 9 numbers.
:Finished
echo.
rem Clean up environment.
set digits=
set thisdigit=
set ziperror=

The following lines are for the batch file "onedigit.bat", which is used to process each digit in the zip code.
set thisdigit=
if %1==1 set thisdigit=...II
if %1==2 set thisdigit=..I.I
if %1==3 set thisdigit=..II.
if %1==4 set thisdigit=.I..I
if %1==5 set thisdigit=.I.I.
if %1==6 set thisdigit=.II..
if %1==7 set thisdigit=I...I
if %1==8 set thisdigit=I..I.
if %1==9 set thisdigit=I.I..
if %1==0 set thisdigit=II...
if _%thisdigit%==_ set ziperror=YES
set digits=%digits%%thisdigit%

No comments:

Post a Comment