Board logo

标题: doc2txt 批量转换 [打印本页]

作者: matlan     时间: 2009-6-21 05:14    标题: doc2txt 批量转换

除转换doc外,还支持rtf、html转换
ON ERROR RESUME NEXT
Set fsObject = CreateObject ("Scripting.FileSystemObject")
myDocDir=wscript.arguments(0)
if myDocDir="" then msgbox "请把要转换的文件夹拖到该图标上",,"提示" : wscript.quit
If Not (fsObject.FolderExists(myDocDir)) Then
        MsgBox myDocDir & "源文件夹不存在,程序终止。", vbCritical, "错误"
          Wscript.Quit
End If

If InStrRev(myDocDir, "\") < Len(myDocDir) Then
        myDocDir = myDocDir & "\"
End If

Set DocFilesDir = fsObject.Getfolder(myDocDir)
Set myDocFiles = DocFilesDir.Files
Set myObject = Wscript.CreateObject("Word.Application")

n = 0
For Each DocFile In myDocFiles
    hz=LCase(Right(DocFile.Name,3))
        If hz = "doc" or hz="rtf" or hz="tml" or hz="htm" Then
                  TextFileName =myDocDir  & Left(DocFile.Name,InStrRev (DocFile.Name, ".")) & "txt"
               
                    myObject.Documents.Open DocFile.Path,,,,,,,,,,,False
                    myObject.Documents(DocFile.Path).Activate
                    myObject.ActiveDocument.SaveAs TextFileName, 2
                    myObject.ActiveDocument.Close
                    n = n + 1
           End If
            
Next

If n > 0 Then
        MsgBox n & "个文件成功转换!"
Else
        MsgBox "转换失败!"
End If
myObject.Quit
Set myObject = Nothing

作者: HAT     时间: 2009-6-21 22:57
相关讨论:
http://www.cn-dos.net/forum/viewthread.php?tid=20764
http://www.cn-dos.net/forum/viewthread.php?tid=41001