简体   繁体   English

如何使用antiword将多个.doc文件转换为.docx?

[英]How to convert multiple .doc files to .docx using antiword?

This manual command is working:此手动命令有效:

!antiword "test" > "test.docx"

but the following script convert files to empty.docx files:但以下脚本将文件转换为 empty.docx 文件:

for file in os.listdir(directory):
    subprocess.run(["bash", "-c", "antiword \"$1\" > \"$1\".docx", "_", file])

also it stores the.docx file in the previous directly eg file is in \a\b this command will store the files to \a它还直接将.docx文件存储在以前的文件中,例如文件在\a\b这个命令会将文件存储到\a

I have tried many different ways including running directly on terminal adn bash loops.我尝试了许多不同的方法,包括直接在终端和 bash 循环上运行。 ony the manual way works.只有手动方式有效。

Something like this should work (adjust dest_path etc. accordingly).像这样的东西应该可以工作(相应地调整dest_path等)。

import os
import shlex

for filename in os.listdir(directory):
    if ".doc" not in filename:
        continue
    path = os.path.join(directory, filename)
    dest_path = os.path.splitext(path)[0] + ".txt"
    cmd = "antiword %s > %s" % (shlex.quote(path), shlex.quote(dest_path))
    print(cmd)
    # If the above seems to print correct commands, add:
    # os.system(cmd)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM