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:][Path] FileName [BatchParameters]] [:label [arguments]]
ex)
- echo
syntax echo [{on|off}] [message]
ex)
- setlocal
- endlocal
ex)
- for
syntax for {%variable|%%variable} in (set) do command [ CommandLineOptions]
ex)
- goto
syntax goto label
- if
syntax
- rem
- shift
ex)
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:][Path] FileName [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.
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
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|%%variable} in (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
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 [not] errorlevel number command [else expression]
if [not] string1==string2 command [else expression]
if [not] exist FileName command [else expression]
If command extensions are enabled, use the following syntax:
if [/i] string1 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@echo off
format a: /s
if not errorlevel 1
goto end
echo An error occurred during formatting.
:end
echo End of batch program.
- 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
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