title: How to convert .docx to .txt in Python
body: <p>I would like to convert a large batch of MS Word files into the plain text format. I have no idea how to do it in Python. I found the following code online. My path is local and all file names are like cx-xxx (i.e. c1-000, c1-001, c2-000, c2-001 etc.):</p>
  <pre><code>from docx import [name of file]
  import io
  import shutil
  import os
  
  def convertDocxToText(path):
  for d in os.listdir(path):
      fileExtension=d.split(&quot;.&quot;)[-1]
      if fileExtension ==&quot;docx&quot;:
          docxFilename = path + d
          print(docxFilename)
          document = Document(docxFilename)
          textFilename = path + d.split(&quot;.&quot;)[0] + &quot;.txt&quot;
          with io.open(textFilename,&quot;c&quot;, encoding=&quot;utf-8&quot;) as textFile:
              for para in document.paragraphs: 
                  textFile.write(unicode(para.text))
  
  path= &quot;/home/python/resumes/&quot;
  convertDocxToText(path)
  </code></pre>