温馨提示×

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

养鱼的猫咪
489
2021-03-08 13:58:33
栏目: 编程语言

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

0