python实现将文件夹下面的不是以py文件结尾的文件都过滤掉的方法

yipeiwu_com6年前Python基础

如下所示:

dir_in = os.path.join(os.path.dirname(__file__), r"oldApp")
    dir_in = unicode(dir_in, r"GBK")
    dir_out = os.path.join(os.path.dirname(__file__), r"newApp")
    dir_out = unicode(dir_out, r"GBK")


    rediret_file_path_list = []
    soure_file_path_out_list = []
    for root, dirs, files in os.walk(dir_in):
        for file in files:
            # print('root=%s' %root)
            # print('1111 file=%s' %file)
            # filter file extend name not .py
            filter_file = file.split('.')
            if filter_file[1] != 'py':
                continue


            soure_file_path_out = os.path.join(root, file)
            # print(soure_file_path_out)
            soure_file_path_out_list.append(soure_file_path_out)
            root_new = root.replace(r'oldApp', r'newApp')
            if not os.path.exists(root_new):
                os.makedirs(root_new)
            rediret_file_path = os.path.join(root_new, file)
            # print('rediret_file_path=%s' %rediret_file_path)
            rediret_file_path_list.append(rediret_file_path)

以上这篇python实现将文件夹下面的不是以py文件结尾的文件都过滤掉的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python操作redis实例小结【String、Hash、List、Set等】

本文实例总结了Python操作redis方法。分享给大家供大家参考,具体如下: python连接方式可参考:/post/161353.htm 这里介绍详细使用 1、String 操作 r...

详解django2中关于时间处理策略

详解django2中关于时间处理策略

一、django中数据模型关于时间字段的认识 1、 DateField :可以记录年月日,映射到数据库是 date 类型 2、 DateTimeField :可以记录年月日时分秒,映射到...

python 利用浏览器 Cookie 模拟登录的用户访问知乎的方法

python 利用浏览器 Cookie 模拟登录的用户访问知乎的方法

首先在火狐浏览器上登录知乎,然后使用火狐浏览器插件 Httpfox 获取 GET 请求的Cookie,这里注意使用状态值为 200(获取成功)的某次GET. 将 Cookies 复制出...

python Opencv计算图像相似度过程解析

python Opencv计算图像相似度过程解析

这篇文章主要介绍了python Opencv计算图像相似度过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 一、相关概念 一般...

Python实现的Excel文件读写类

本文实例讲述了Python实现的Excel文件读写类。分享给大家供大家参考。具体如下: #coding=utf-8 #################################...