中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-12 20:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » VBS--谁写个txt文件删除添加某行的调用啊 查看 681 回复 2
楼 主 VBS--谁写个txt文件删除添加某行的调用啊 发表于 2010-01-20 17:17 ·  中国 安徽 马鞍山 电信
社区乞丐
积分 -27
发帖 45
注册 2006-05-16 11:25
20年会员
UID 55616
状态 离线
比如c:\1.txt
a
b
c
我要删除第2行返回
a
c

或我要添加第2行,添加数据是*,返回
a
*
b
c

谁给写个简洁点的Function吧
2 发表于 2010-01-21 10:53 ·  中国 北京 中电华通通信有限公司
高级用户
★★★
据说是李先生
积分 609
发帖 400
注册 2008-04-23 15:55
18年会员
UID 116706
性别 男
状态 离线

DeleteLine "c:\1.txt", 2
InsertLine "c:\1.txt", 2, "*"

Sub DeleteLine(filespec, rownum)
Dim fso, f, temp, i
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filespec, 1)
temp = ""
i = 0
While Not f.AtEndOfStream
i = i + 1
If Not i = rownum Then
temp = temp & f.ReadLine & vbCrLf
Else
f.SkipLine
End If
WEnd
f.Close
Set f = fso.OpenTextFile(filespec, 2)
f.Write temp
f.Close
End Sub


Sub InsertLine(filespec, rownum, oneline)
Dim fso, f, temp, i
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filespec, 1)
temp = ""
i = 0
While Not f.AtEndOfStream
i = i + 1
If i = rownum Then temp = temp & oneline & vbCrLf
temp = temp & f.ReadLine & vbCrLf
WEnd
f.Close
Set f = fso.OpenTextFile(filespec, 2)
f.Write temp
f.Close
End Sub

┏━━━━━━┓
┃据说是李先生┃
┠──────┨
┃*ntRSS┃
┗━━━━━━┛
3 发表于 2010-01-21 13:36 ·  中国 重庆 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
sed很好很简洁
论坛跳转: