os/windows

windows batch file

뚜벅이조 2011. 8. 17. 11:09
wiki :  http://en.wikipedia.org/wiki/Batch_file  
syntax : http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true  

- summary

-argument
%1~9

- call
syntax call [[Drive:][PathFileName [BatchParameters]] [:label [arguments]]
ex)
1 call checknew %1 %2
 


- echo
syntax echo [{on|off}] [message]
ex)
1 echo off
2 echo.
3 echo This batch program
4 echo formats and checks
5 echo new disks
6 echo.

- setlocal

- endlocal

ex)
1 @echo off
2 rem This program starts the superapp batch program on the network,
3 rem directs the output to a file, and displays the file
4 rem in Notepad.
5 setlocal
6 path=g:\programs\superapp;%path%
7 call superapp>c:\superapp.out
8 endlocal
9 start notepad c:\superapp.out

- for
syntax for {%variable|%%variablein (set) do command [ CommandLineOptions]
ex)
for %f in (*.doc *.txt) do type %f
for /F "eol=; tokens=2,3* delims=," %i in (myfile.txt) do @echo %i %j %k
for /F "usebackq delims==" %i IN (`set`) DO @echo %i
 

- goto
syntax goto label

- if
syntax

if [noterrorlevel number command [else expression]

if [notstring1==string2 command [else expression]

if [notexist FileName command [else expression]

If command extensions are enabled, use the following syntax:

if [/istring1 CompareOp string2 command [else expression]

if cmdextversion number command [else expression]

if defined variable command [else expression]

ex)

:begin
 
@echo off
 
format a: /s
 
if not errorlevel 1
 
goto end
 
echo An error occurred during formatting.
 
:end
 
echo End of batch program.
 
- pause
- rem
- shift
ex)
@echo off
rem MYCOPY.BAT copies any number of files
rem
to a directory.
rem
The command uses the following syntax:
rem
mycopy dir file1 file2 ...
set todir=%1 :getfile
shift
if "%1"=="" goto end
copy %1 %todir%
goto getfile
:end
set todir=
echo All done