您好,登錄后才能下訂單哦!
小編給大家分享一下使用python實(shí)現(xiàn)將文件夾下面的不是以py文件結(jié)尾的文件都過(guò)濾掉的案例,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
如下所示:
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)
看完了這篇文章,相信你對(duì)“使用python實(shí)現(xiàn)將文件夾下面的不是以py文件結(jié)尾的文件都過(guò)濾掉的案例”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。