因为 fso.opentextfile 不支持 utf-8
自动判断编码并处理:- <script src=http://bbs.bathome.net/lib/diy/WSH.js></script>
- <script src=http://bbs.bathome.net/lib/diy/iconv.js></script>
-
- <script language=vbscript>
- on error resume next
-
- Dim FSO,s
- Set FSO=CreateObject("Scripting.FileSystemObject")
- Set AllF=FSO.GetFolder(fso.GetParentFolderName (WScript.ScriptFullName ))
- For Each file In AllF.Files
- If Right(file,3)="txt" Then
- zhuanhuan CStr(file)
- End If
- Next
-
- msgbox "已经将所有文本文件转换成WORD文件!",48+4096,"操作成功"
-
- sub zhuanhuan(filename)
- name=fso.getbasename(filename)
-
- s=""
- bin = iconv.load(filename)
- If Not isNull(bin) Then
- bom = iconv.checkBom(bin)
- If bom="undefined" Then bom="gb2312"
- s=iconv.toStr(bin,bom)
- End If
-
- Set objWord = CreateObject("Word.Application")
- 'objWord.Visible = True
- Set objDoc = objWord.Documents.Add()
- For i = 1 To Len(s) Step 20000
- objword.Selection.TypeText Mid(s, i, 20000)
- Next
- objword.ActiveDocument.SaveAs AllF & "\" & name & ".doc"
- objword.quit
- end Sub
- </script>
复制代码
|