Linux 拨号vps windows公众号手机端

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

lewis 6年前 (2019-03-30) 阅读数 10 #程序编程
文章标签 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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门