Board logo

标题: [原创]给BAT文件添加注释头 [打印本页]

作者: SpikeKnox     时间: 2007-2-1 12:36    标题: [原创]给BAT文件添加注释头

@Echo OFF
::
:: BatName: AddBatHead.bat
:: Version: 0.1
:: Purpose: 给BAT文件添加注释头
::
:: Usage: AddBatHead BatFile
:: BatFile bat file who what head.
:: LineNumber where to insert. *default is 0
::
::
:: sed.exe
::
:: Code by SpikeKnox 2007.01.20
::

rem Show help
If == (Type "%~f0" | findstr "^::" && Goto :EOF)

rem %1 BatFile
If NOT EXIST %1 (Type "%~f0" | findstr "^::" && Goto :EOF)

rem %2 LineNumber
If == ( Set line=0 ) Else ( Set line=%2 )

Pushd "%~dp1"
Set head=head.txt

rem
>%head% Echo ::
>>%head% Echo :: BatName: %~nx1
>>%head% Echo :: Version: 0.1
>>%head% Echo :: Purpose:
>>%head% Echo ::
>>%head% Echo :: Usage: %~n1
>>%head% Echo ::
>>%head% Echo ::
>>%head% Echo ::
>>%head% Echo :: Code by SpikeKnox %DATE%
>>%head% Echo ::
>>%head% Echo.
>>%head% Echo rem Show help
>>%head% Echo If == (Type "%%~f0" ^| findstr "^::" ^&^& Goto :EOF)
>>%head% Echo.

If %line% EQU 0 (
Copy /b %head%+"%~f1" "%~f1_new.tmp" > NUL
) Else (
sed "%line%r %head%" "%~f1" > "%~f1_new.tmp"
)

rem
Move /y "%~f1_new.tmp" "%~f1" > NUL

rem
Set line=
Del head.txt
Set head=

Popd