# encoding: utf-8
'''
@file: readFilePath.py
@time: 2022/10/19
@author: zpj
'''
import os
# 查找指定文件夹下所有相同后缀名的文件
def search_sameSuffix_file(dirPath, suffix):
dirs = os.listdir(dirPath)
for currentFile in dirs:
fullPath = dirPath + '/' + currentFile
if os.path.isdir(fullPath):
search_sameSuffix_file(fullPath, suffix)
elif currentFile.split('.')[-1] == suffix:
print(fullPath)
# 保存获取到的文件路径写入txt
f = open('filePath.txt', 'a+')
f.write(fullPath + '\n')
f.close()
if __name__ == "__main__":
# 添加文件夹路径
dirPath = ' '
# 添加文件后缀名
suffix = ' '
search_sameSuffix_file(dirPath, suffix)
Python查找文件夹下所有指定后缀名的文件路径
最新推荐文章于 2024-10-11 09:56:03 发布
Python3.8
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
您可能感兴趣的与本文相关的镜像
Python3.8
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
772

被折叠的 条评论
为什么被折叠?



