Python implements a method to filter out all files under the folder that are not ending with py files.
Updated: October 21, 2018 15:00:38 Author: zhangyulin54321
Today, the editor will share with you a python method to filter out all files under the folder that are not ending with py files. It has good reference value and hope it will be helpful to everyone. Let's take a look with the editor
As shown below:
dir_in = ((__file__), r"oldApp") dir_in = unicode(dir_in, r"GBK") dir_out = ((__file__), r"newApp") dir_out = unicode(dir_out, r"GBK") rediret_file_path_list = [] soure_file_path_out_list = [] for root, dirs, files in (dir_in): for file in files: # print('root=%s' %root) # print('1111 file=%s' %file) # filter file extend name not .py filter_file = ('.') if filter_file[1] != 'py': continue soure_file_path_out = (root, file) # print(soure_file_path_out) soure_file_path_out_list.append(soure_file_path_out) root_new = (r'oldApp', r'newApp') if not (root_new): (root_new) rediret_file_path = (root_new, file) # print('rediret_file_path=%s' %rediret_file_path) rediret_file_path_list.append(rediret_file_path)
Related Articles
Django custom filter definition and usage example
This article mainly introduces the definition and usage of Django custom filters. It analyzes the concept, function, definition and usage of Django custom filters in combination with examples. Friends who need it can refer to it.2018-03-03Detailed explanation of the instructions for using the Python Pexpect module
Today, the editor will share with you a detailed explanation of the instructions for using the Python Pexpect module. It has good reference value and hope it will be helpful to everyone. Let's take a look with the editor2019-02-02Introduction to the properties and methods of classes in python
In this article, the editor has compiled an introduction to the attribute knowledge points and usage methods of classes in python. Friends who need it, please refer to it.2018-11-11Application of HMAC encryption algorithm in Python
The HMAC algorithm can be used to verify the integrity of information passed between applications or stored in potentially vulnerable locations. Therefore, this article has compiled some applications of HMAC encryption algorithms in Python for you, hoping to be helpful to you.2023-05-05Detailed explanation of OpenCV shape detection example
This article mainly introduces the shape detection in OpenCV. The example code is introduced in this article in detail, which has certain reference learning value for everyone's study or work. Friends who need it, please learn with the editor below.2022-08-08Analysis of the implementation steps of Python connection Impala
This article mainly introduces the analysis of the implementation steps of Python connection Impala. The example code is introduced in this article in detail, which has certain reference value for everyone's learning or work. Friends who need it can refer to it.2020-08-08Solve the problem of swapping two rows and assignment of numpy arrays
This article mainly introduces the problem of solving the problem of swapping two rows and assignment of numpy arrays. It has good reference value and hopes it will be helpful to everyone. Let's take a look with the editor2021-04-04Python method of stating the frequency of occurrence and sorting of given iterable sets
Today, the editor will share with you a python method of stating the frequency and sorting of given iterable sets, which is of good reference value. I hope it will be helpful to you. Let's take a look with the editor2018-10-10Use of python namedtuple function
Today, we introduce a useful small function in collections: namedtuple function (can have the convenience of class without creating a class), for example, you can use it2021-06-06Explanation on the use of ARIMA model in Python time series processing
Today, the editor will share with you an explanation of the use of the ARIMA model for Python time series processing. The editor thinks the content is quite good. Now I share it with you. It has good reference value. Friends in need will follow the editor to take a look.2019-04-04