溫馨提示×

python遍歷查找文件夾中符合要求的文件

養魚的貓咪
514
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
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女