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)

猜你喜欢

转载自www.cnblogs.com/chaojiyingxiong/p/10986056.html