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进行文本预处理和提取特征的实例

如下所示: <strong><span style="font-size:14px;">文本过滤</span></strong>...

Django视图扩展类知识点详解

扩展类必须配合GenericAPIView使用扩展类内部的方法,在调用序列化器时,都是使用get_serializer 需要自定义get、post等请求方法,内部实现调用扩展类对应方法即...

python3中zip()函数使用详解

zip在python3中,处于优化内存的考虑,只能访问一次!!!(python2中可以访问多次),童鞋们一定要注意, * coding: utf-8 * zip()函数的定...

tensorflow获取变量维度信息

tensorflow版本1.4 获取变量维度是一个使用频繁的操作,在tensorflow中获取变量维度主要用到的操作有以下三种: Tensor.shape Tensor.get...

Python 通过截图匹配原图中的位置(opencv)实例

Python 通过截图匹配原图中的位置(opencv)实例

安装依赖 1)下载安装opencv-2.4.9,并将cv2.pyd拷贝到python安装目录的site-package下 2)pip install numpy 3)pip instal...