阅读背景:

Python读取指定目录下的指定后缀文件名列表(批量读取)

来源:互联网 

一、获取指定目录下、指定后缀的文件名列表 

"""
函数说明:获取指定目录下的、指定后缀的文件
    例如:.xlsx、.json

Parameters:
    path - 目录所在的路径 例如 path='D:\Python Example\Tianyancha\Data'
    suffix  -  后缀,例如'.xlsx'
Returns:
    input_template_All - 指定后缀的所有文件名
Author:
    heda3
Blog:
    https://blog.csdn.net/heda3
Modify:
    2019-10-12
"""
#参考:https://www.runoob.com/python/os-listdir.html
def getFileName1(path,suffix):
    # 获取指定目录下的所有指定后缀的文件名 
    input_template_All=[]
    f_list = os.listdir(path)#返回文件名
    for i in f_list:
        # os.path.splitext():分离文件名与扩展名
        if os.path.splitext(i)[1] ==suffix:
            input_template_All.append(i)
            #print(i)
    return input_template_All"""
函数说明:获取指定



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: