Created
January 11, 2010 17:49
-
-
Save yinyin/274422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is a Windows Script Host script file written in JScript. You will need Word | |
* installed on your system before get this script running. | |
* The purpose of this script is convert multiple Word files (*.doc) into HTML files | |
* via Word's "Save As" function. | |
* User have to place the files into a folder and double-click on this script. A folder | |
* selection dialog will appear than you shall know what to do. */ | |
WScript.Echo( "Please make sure all Word windows have been closed before proceed." ); | |
var objShell = new ActiveXObject("Shell.Application"); | |
var objSrcFolder; | |
var objTgtFolder; | |
objSrcFolder = objShell.BrowseForFolder(0, "Select the source folder which contains Word (*.doc) files to be converted.", 0, 0); | |
objTgtFolder = objShell.BrowseForFolder(0, "Select the target folder which stores the resulted HTML files.", 0, 0); | |
if( (null != objSrcFolder) && (null != objTgtFolder) ) | |
{ | |
var oFolderItems = objSrcFolder.Items(); | |
var WordApp = new ActiveXObject("Word.Application"); | |
var WordDocs = WordApp.Documents; | |
WordApp.Visible = true; | |
var convertCount = 0; | |
for(var i=0; i<oFolderItems.Count; i++) { | |
var oFileItem = oFolderItems.Item(i); | |
if( (true != oFileItem.IsFolder) && (true != oFileItem.IsLink) ) | |
{ | |
var strSrcPath = oFileItem.Path; | |
var strExt = strSrcPath.substr(strSrcPath.length-4, 4).toLowerCase(); | |
if(".doc" == strExt) | |
{ | |
var strFileName = oFileItem.Name; | |
strFileName = strFileName.substr(0, strFileName.length-4); | |
var oSubjectItem = objTgtFolder.Self.Path+"\\"+strFileName+".html"; | |
// WScript.Echo( oSubjectItem + " - "+strFileName ); | |
var DocDoc = WordDocs.Open(strSrcPath, false, true, false); | |
DocDoc.SaveAs(oSubjectItem, 10); | |
DocDoc.Close(); | |
convertCount++; | |
} | |
} | |
} | |
WordApp.Quit(); | |
WScript.Echo( "Operation completed ! "+convertCount+" documents converted." ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment