txt文件合并

本以为很简单,代码也写了好几行,关键问题,读utf8编码的问题

Dim fso,distFile,objfol,sourceFile

 

       dim stm

 

set stm=CreateObject("adodb.stream")

 

stm.Type=2 '以本模式读取

 

stm.mode=3

 

stm.charset="UTF-8"

 

 

Set fso = CreateObject("Scripting.FileSystemObject")

 

Set distFile = fso.CreateTextFile("g:\ming.txt", True) '如存在则重写

 

Dir = "D:\msnfile\mingchao\"

'dir = "D:\msnfile\a\"

Set objfol=fso.GetFolder(dir) 

 

For Each objf In objfol.Files 

       'MsgBox objf.Name

 

 stm.open      

 

stm.loadfromfile  dir & objf.Name

 

content=stm.readtext

 

stm.Close

 

 

 

 

'Set sourceFile = fso.OpenTextFile(dir & objf.Name, 1, False, -2) '-2 -1 0

'content = sourceFile.ReadAll

distFile.writeline content

 

Next 

 

distFile.close()

 

Set sourceFile = Nothing

Set distFile = Nothing

Set fso= Nothing

Set stm=Nothing

 

'TristateUseDefault –2 使用系统缺省打开文件。  

'TristateTrue –1 以 Unicode 格式打开文件。  

'TristateFalse 0 以 ASCII 格式打开文件。 

你可能感兴趣的:(txt文件合并)