python中用os.walk查找所有的子文件

import os
import shutil

#  要遍歷查找的文件所在的父文件夾
trajectory_filename =r"D:\mapping"

#  要粘貼到的目標文件夾
sources_folder = r'D:\map'

for root, dirs, files in os.walk(trajectory_filename):
    for name in files:
        # print(os.path.join(root, name))
        if "png" in os.path.join(root, name) and "txt" not in os.path.join(root, name) and "las" not in os.path.join(root, name):
            print(os.path.join(root, name))
            shutil.copy(os.path.join(root, name), sources_folder)
相關文章
相關標籤/搜索