Page 1 of 2
Possible to convert M$ Word Doc into .TXT?
Posted: 18 Jul 2013 06:54
by LiuKang
Hi!
I have a many different folders that contains alot of Microsoft Word 97 - 2003 Documents.
I want to go into a folder and execute a .bat which convert these into a new folder within the current folder with .txt as output.
Is this possible?
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 18 Jul 2013 07:21
by foxidrive
VBS might have the ability to interact with Word but failing that an AutoIt script could press the buttons to do it, I think.
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 18 Jul 2013 08:35
by brinda
hi,
in case if microsoft office is not available in the pc to convert than can use below
there is one software that we were using for a very long time for comparison purpose
the main page is in japanese but google nearly translate the correct word.
http://www31.ocn.ne.jp/~h_ishida/xdoc2txt.htmltranslate
Code: Select all
http://translate.google.com/translate?hl=en&sl=ja&u=http://www31.ocn.ne.jp/~h_ishida/xdoc2txt.html&prev=/search%3Fq%3Dhttp://www31.ocn.ne.jp/~h_ishida/xdoc2txt.html%26client%3Dfirefox-a%26hs%3D1zV%26rls%3Dorg.mozilla:en-US:official
can be used from win95 to the latest version. really fast. it can convert the ofice excel/word/powerpoint and other format to txt. small file size but huge support for different formats.
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 18 Jul 2013 14:50
by npocmaka_
Yes , you can .But you'll have to use jscript, vbscript or powershell. Here's how you can open document->
http://msdn.microsoft.com/en-us/library ... =office.11).aspx
here are save constants
http://msdn.microsoft.com/en-us/library ... 39952.aspxIf have a time I 'll create a script tomorrow
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 19 Jul 2013 01:19
by npocmaka_
This is a
hybrid bat/vbscript and need to be saved as .bat:
Code: Select all
'>nul 2>&1|| @copy /Y %windir%\System32\doskey.exe %windir%\System32\'.exe >nul
'&&@echo off && cls &&goto :end_vbs
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = FALSE
'Open doc for reading
Set WordDoc = WordApp.Documents.Open(WScript.Arguments.Item(0),true)
'wdFormatText 2
'wdFormatUnicodeText 7
format = CInt(WScript.Arguments.Item(2) )
WordDoc.SaveAs WScript.Arguments.Item(1) ,format
WordDoc.Close()
WScript.Quit
:end_vbs
'& if "%~1" equ "-help" echo %~n0 word_document [ destination [-unuicode] ]
'& if "%~1" equ "" echo word document not given & exit /b 1
'& if not exist "%~f1" echo word document does not exist & exit /b 2
'& if "%~2" equ "" ( set "save_as=%~n1.txt") else ( set "save_as=%~2")
'& if exist "%~f2" del /s /q "%~f2"
'& if "%~3" equ "-unuicode" ( set "format=7") else ( set "format=2")
'& taskkill /im winword* /f >nul 2>&1
'& cscript /nologo /E:vbscript %~f0 "%~f1" "%save_as%" %format%
'& pause
'& rem del /q %windir%\System32\'.exe
To start not visible word application and copying to %windir%\System32\ requires admin privileges , so you'll have to run this as administrator.
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 19 Jul 2013 03:51
by foxidrive
That's an interesting use of doskey.

Re: Possible to convert M$ Word Doc into .TXT?
Posted: 19 Jul 2013 05:30
by npocmaka_
foxidrive wrote:That's an interesting use of doskey.

Subst.exe (and a bunch of exes in system32 that I don't know what in fact are doing) also can be used but I prefer doskey because I know that will do anything in a batch file and is fast enough.
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 19 Jul 2013 15:58
by Samir
foxidrive wrote:That's an interesting use of doskey.

I saw that and am totally confused.

Re: Possible to convert M$ Word Doc into .TXT?
Posted: 19 Jul 2013 16:39
by npocmaka_
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 19 Jul 2013 18:42
by foxidrive
I'll drop a hint...
This command line generates an error message.
Code: Select all
d:\abc>'& rem
''' is not recognized as an internal or external command,
operable program or batch file.
Note that every line in the batch code section starts with '&
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 20 Jul 2013 17:15
by Samir
So I kinda follow the vbscript, but don't know why you copy doskey and delete it at the end.
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 21 Jul 2013 02:30
by npocmaka_
In fact the deleting is commented but could be uncommented.
I'm copying to doskey to '.exe somewhere in the %PATH% so after that it can be called as '&.
In vbscript this is a comment , but for the batch means execute '.exe and then the next command.
As doskey does do nothing in bat file (especially without parameters) and is fast enough in fact this will mean - do nothing and then execute the next command.
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 21 Jul 2013 13:57
by Samir
npocmaka_ wrote:In fact the deleting is commented but could be uncommented.
I'm copying to doskey to '.exe somewhere in the %PATH% so after that it can be called as '&.
In vbscript this is a comment , but for the batch means execute '.exe and then the next command.
As doskey does do nothing in bat file (especially without parameters) and is fast enough in fact this will mean - do nothing and then execute the next command.
WOW. I'm totally in awe. I've been a batch file junkie since the days of DOS 3.3, and I never knew about the '&. I tested it out on the command line using
expecting
as my result. But instead I got what you just taught me
Code: Select all
'
'tezt' is not recognized as an internal or external command,
operable program or batch file.
Where did you learn about '&? I'd love to read up on it some more.
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 21 Jul 2013 20:13
by foxidrive
It's not `& as a term.
` is the new command you created by copying doskey.exe and & is the command separator since Windows NT was introduced.
Re: Possible to convert M$ Word Doc into .TXT?
Posted: 21 Jul 2013 22:04
by Samir
foxidrive wrote:It's not `& as a term.
` is the new command you created by copying doskey.exe and & is the command separator since Windows NT was introduced.
Ahh, that makes a bit more sense. I remember using && in if, but didn't realize it was more than that after NT. Good stuff.
