楼 主
[原创]给BAT文件添加注释头
发表于 2007-02-01 12:36 · 中国 浙江 杭州 华数
初级用户
★
积分 116
发帖 28
注册 2007-01-03 05:21
19年会员
UID 75318
性别 男
状态 离线
@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
论坛跳转: