为程序代码或文本文件添加行号的批处理文件
作者:parno 日期:2010-03-02
复制内容到剪贴板
程序代码
![程序代码](images/code.gif)
@echo off
if "%1"=="" echo 没有设置要添加行号的文件名!&goto noemm
if not exist %1 echo 文件 %1 不存在!&goto noemm
echo 正在添加行号,请稍等...
set num=0
setlocal enabledelayedexpansion
for /f "delims=" %%i in (%1) do (
set /a num+=1
set str=%%i
echo !num! !str! >> new_%1
)
echo 行号添加完成,已保存到文件 new_%1。
goto exit
:noemm
echo.
echo 功能:在指定文本文件的每一行添加行号,并保存为新文件。
echo 使用方法:%0 names
echo.
:exit
if "%1"=="" echo 没有设置要添加行号的文件名!&goto noemm
if not exist %1 echo 文件 %1 不存在!&goto noemm
echo 正在添加行号,请稍等...
set num=0
setlocal enabledelayedexpansion
for /f "delims=" %%i in (%1) do (
set /a num+=1
set str=%%i
echo !num! !str! >> new_%1
)
echo 行号添加完成,已保存到文件 new_%1。
goto exit
:noemm
echo.
echo 功能:在指定文本文件的每一行添加行号,并保存为新文件。
echo 使用方法:%0 names
echo.
:exit
[本日志由 parno 于 2010-03-08 11:20 PM 编辑]
![](images/Cprevious.gif)
![](images/Cnext.gif)
![](images/From.gif)
![](images/icon_trackback.gif)
![](images/tag.gif)
![](images/notify.gif)
评论: 0 | 引用: 0 | 查看次数: 8868
发表评论