China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-12 01:37
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Add a comment header to BAT files View 751 Replies 0
Original Poster Posted 2007-02-01 12:36 ·  中国 浙江 杭州 华数
初级用户
Credits 116
Posts 28
Joined 2007-01-03 05:21
19-year member
UID 75318
Gender Male
Status Offline

@Echo OFF
::
:: BatName: AddBatHead.bat
:: Version: 0.1
:: Purpose: Add a comment header to BAT files
::
:: 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
Forum Jump: