python实现将文件夹下面的不是以py文件结尾的文件都过滤掉的方法
如下所示:
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=[] forroot,dirs,filesinos.walk(dir_in): forfileinfiles: #print('root=%s'%root) #print('1111file=%s'%file) #filterfileextendnamenot.py filter_file=file.split('.') iffilter_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') ifnotos.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文件结尾的文件都过滤掉的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。