Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bunch of .txt files, sorted in different folders. I need to convert all of .txt files to .doc files.

I have Googled the issue and found that I could just change the extension to .doc. But this doesn't seem to work, as Word still wants to convert the file when i open it. And no matter which option i use to convert (Text only, Unicode text, etc.) the file doesn't convert special characters, such as –, æ, ø, å (which is common in my language :) ).

I have tried to choose Unicode text and choose Encoding such as "Western (Mac OS Roman)" or "Western (Windows Latin 1)" but none of these convert the special characters properly.

So - I found out, that at simple copy / paste from .txt to .doc works.. but with 100's af files, this would be a tedious manual work.

My question therefore: Is there any way this can be automated?

share|improve this question

1 Answer 1

up vote 2 down vote accepted
cd ~/Documents/folder; textutil -convert doc *.txt

Or if the files are in different folders:

find ~/Documents/folder -name \*.txt -exec textutil -convert doc {} \+
share|improve this answer
    
It may also be necessary to also specify the encoding of the text files as described in the textutil man page. –  martineau Apr 9 '13 at 8:37
    
Wow - that did it! Thank you very much! :) Can you explain what this does different than the manual renaming? –  Crave Apr 9 '13 at 8:53
    
Doc is a binary format (try cat file.doc) so just renaming .txt to .doc shouldn't work. @martineau I have needed -inputencoding UTF-8 when the input was from STDIN, but this seemed to work without it at least for UTF-8 files without a BOM (even with LC_ALL=C). –  Lri Apr 9 '13 at 12:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.