如何使用python显示文件夹中Word文档的文件名?

问题描述 投票:1回答:3

我想使用python显示指定路径中存在的word文档的文件名。

python arrays document docx
3个回答
1
投票

这可能对您有用:

for file in os.listdir(PATH):
    if file.endswith(".doc") or file.endswith(".docx"):
        print(file)

0
投票

它就像使用scandir创建自定义迭代器一样简单,传递文件扩展名(对于Word文档,您可以使用docx)。像这样:


0
投票

@ sxeros方法的替代方法:)

© www.soinside.com 2019 - 2024. All rights reserved.