Possible to convert M$ Word Doc into .TXT?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
LiuKang
Posts: 5
Joined: 16 Jul 2013 04:22

Possible to convert M$ Word Doc into .TXT?

#1 Post by LiuKang » 18 Jul 2013 06:54

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Possible to convert M$ Word Doc into .TXT?

#2 Post by foxidrive » 18 Jul 2013 07:21

VBS might have the ability to interact with Word but failing that an AutoIt script could press the buttons to do it, I think.

brinda
Posts: 78
Joined: 25 Apr 2012 23:51

Re: Possible to convert M$ Word Doc into .TXT?

#3 Post by brinda » 18 Jul 2013 08:35

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.html

translate

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.

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#4 Post by npocmaka_ » 18 Jul 2013 14:50

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.aspx


If have a time I 'll create a script tomorrow

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#5 Post by npocmaka_ » 19 Jul 2013 01:19

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.
Last edited by npocmaka_ on 19 Jul 2013 16:35, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Possible to convert M$ Word Doc into .TXT?

#6 Post by foxidrive » 19 Jul 2013 03:51

That's an interesting use of doskey. :)

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#7 Post by npocmaka_ » 19 Jul 2013 05:30

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.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#8 Post by Samir » 19 Jul 2013 15:58

foxidrive wrote:That's an interesting use of doskey. :)
I saw that and am totally confused. :?:

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#9 Post by npocmaka_ » 19 Jul 2013 16:39

Samir wrote:I saw that and am totally confused. :?:



:twisted: :twisted: :twisted:

Do not hesitate and ask.I'll be glad to explain.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Possible to convert M$ Word Doc into .TXT?

#10 Post by foxidrive » 19 Jul 2013 18:42

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 '&

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#11 Post by Samir » 20 Jul 2013 17:15

npocmaka_ wrote:
Samir wrote:I saw that and am totally confused. :?:



:twisted: :twisted: :twisted:

Do not hesitate and ask.I'll be glad to explain.
So I kinda follow the vbscript, but don't know why you copy doskey and delete it at the end.

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#12 Post by npocmaka_ » 21 Jul 2013 02:30

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.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#13 Post by Samir » 21 Jul 2013 13:57

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

Code: Select all

echo '& tezt
expecting

Code: Select all

'& tezt
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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Possible to convert M$ Word Doc into .TXT?

#14 Post by foxidrive » 21 Jul 2013 20:13

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.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Possible to convert M$ Word Doc into .TXT?

#15 Post by Samir » 21 Jul 2013 22:04

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. 8)

Post Reply