'功能:删除某个文件中内容相同的行,但保留内容相同的最上面的一行。
'弊端:效率太低。处理文件不要太大,请测试后使用。
'使用方法:将下面的内容复制到记事本另存为a.vbs之后把要处理的文件拖放到a.vbs上面即可。
starttime=timer
on error resume next
set fso=createobject("scripting.filesystemobject")
set fd=fso.getfile(Wscript.Arguments(0))
set file=fso.opentextfile(Wscript.Arguments(0),1)
Do while not(file.AtEndOfStream)
n = n + 1
tmp = file.readline
ReDim Preserve temp(n-1)
temp(n-1)= tmp
loop
file.Close
For x=0 to n-1
For y= 1 to n-1
If x <> y Then
If temp(x) =temp (y) And x < y Then
temp(y)="{059F6FBC-10FB-4FBC-BCF7-DB362A3DB1DB}"
End If
End If
Next
Next
For x=0 to n-1
if temp(x)<>"{059F6FBC-10FB-4FBC-BCF7-DB362A3DB1DB}" then S= S & temp(x) & vbcrlf
Next
Set file = fso.OpenTextFile(Wscript.Arguments(0), 2, True)
file.write S
file.Close
endtime=timer
yongshi=cdbl(endtime-starttime)
msgbox "已经将" & fd.name & "文件里相同行的内容删除,用时" & Round(yongshi,2) & "妙。" & vbcrlf & "(保留了相同行内容的最上面的一行!)" ,48+4096,"操作完成"
set fso=nothing
set fd=nothing
set file=nothing
Last edited by jmz573515 on 2006-12-26 at 09:44 AM ]