Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a tool to do this. I've seen some Python/Java tools to automate OpenOffice but has anyone reliably scripted this to do more than one file, and recurse through a folder/directory tree with .doc files in it, placing the converted .txt and .html files next to the original file in its location.

share|improve this question


There are two Unix tools I know of:

  • catdoc
  • antiword

You could just use find to go through the folder recursively

find . -name "*.doc" -exec <command> {} \;

Where <command> is the appropriate action to convert the .doc file into a .txt file, using either catdoc or antiword.

Mac OS X

You can use the same tools, but you'll have to install them using, for example, Homebrew. To do this, enter in the Terminal:

ruby -e "$(curl -fsSL"

And then:

brew install catdoc
brew install antiword
share|improve this answer
+1 for the solution. As in question, Window or Mac please but I also have Ubuntu so hope to be able to use your solution. I'll look it up, try it and if it works then I'll accept your answer. Thanks. – therobyouknow Mar 3 '11 at 8:51
I added installation instructions for OS X in the post. I haven't tried the <command> part yet, but I can look into that if you have any troubles. – slhck Mar 3 '11 at 10:50
+1 thanks for the Mac option too. – therobyouknow Mar 13 '11 at 10:53
up vote 1 down vote accepted

@slhck your solution almost works but the output is to the display / STDOUT with all the files concatenated together. I need individual .txt files as output. Reason is that we're not accounting for the filename in the output.

To work around having to traverse a folder hierarchy If I use Windows search for *.doc and then copy the results to a folder to put them all in one folder flattened, then I can boot into Ubuntu and run the following.

(I have a file/folder recursion piece of code somewhere which I will dig out and add to later if time.) But for now just flattening the file hierachy as above is good enough.

By the way, catdoc works better than antiword because antiword complains some files aren't word docs, these tend to be .doc files with formatting and blocks of text organised as frames within the doc. catdoc seems to convert all of my docs.

#!/usr/bin/perl -w

 use File::Basename;

 my $okFiles = "";
 my $couldntGet = "";

 @files = <*>;
 foreach $file (@files) 
   if ( $file =~ m/\.doc/ )
     my ( $filenameOnly, $dir, $ext ) = fileparse($file, qr/\.[^.]*/);
     if ( ( defined $filenameOnly ) && ( defined $ext ) )
       $okFiles .= "file: ".$file." filename only:".$filenameOnly." extension:".$ext."\n";

       system( "catdoc \"".$file."\" > \"".$filenameOnly.".txt\"" );
       $couldntGet .= "*file: ".$file." - couldn't get filename only and extension\n";

   print $okFiles;

   print $couldntGet;
share|improve this answer

catdoc and antiword have very limited file format support, the latest version they understand is Word 2000.

I know you can script LibreOffice to convert any files it understands to text or pdf (this is what MediaGoblin does) but I don't know how exactly to do that.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .