扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python遍历查找文件夹中符合要求的文件

扬州沐宇科技
2021-03-08 13:58:33
python, 遍历

python遍历查找文件夹中符合要求的文件

在python中使用遍历查找出文件夹中符合要求的文件,具体方法如下:

import os

import string

inputFilePath= "G:\\aaa\\shixun_data"

threefile = [ ]

key = "ND"

for file in os.listdir(inputFilePath):

if os.path.splitext(file)[1] == '.tif': # 查找.tif文件

if string.find(file, key) != -1: # 满足条件往下进行

sourcefile = os.path.join(inputFilePath, file) # 拼路径

threefile.append(sourcefile)

print threefile

扫码添加客服微信