===============================
如文本:temp.txt
lcuky"good
CYY_eric"flavour
CYY_eric"flavour
lcuky"good
CYY_eric"flavour
有"符号行,就不行
输出结果为:
CYY_eric
lcuky
===============================
如果把"改成|
如文本:temp.txt
lcuky|good
CYY_eric|flavour
CYY_eric|flavour
lcuky|good
CYY_eric|flavour
就可以,输出结果为正确:
lcuky|good
CYY_eric|flavour
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FolderExists("ok")) then
Set fd = fso.CreateFolder("ok")
Else
Set fd = fso.GetFolder("ok")
End If
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
strPathToTextFile = ".\id\"
Set fs = fso.GetFolder("id")
Set fs = fs.Files
For Each f in fs
If fso.GetExtensionName(f.Name)="txt" then
strFile = f.Name
Set MyFile = fso.CreateTextFile(fd.Name&"\"&f.Name,true)
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=NO;FMT=Delimited"""
objRecordSet.Open "Select DISTINCT * FROM " & strFile,_
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordSet.EOF
MyFile.WriteLine objRecordSet.Fields.Item(0).Value
objRecordSet.MoveNext
Loop
MyFile.Close
Set Myfile = Nothing
objRecordSet.Close
objConnection.Close
End If
Next
Set fs = Nothing
Set fd = Nothing
Set fso = Nothing
Set objRecordSet = Nothing
Set objConnection = Nothing
MsgBox "去除成功"