温馨提示×

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

养鱼的猫咪
499
2021-03-08 13:58:33
栏目: 编程语言
Python开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:在windows中怎么查找文件或文件夹

0