#!/usr/bin/env python3 # -*- coding:utf8 -*- # @TIME :2018/9/17 9:02 # @Author:dazhan # @File :copyfiles2dir.py import os import shutil source_path = os.path.abspath(r'Z:\webscraping\output\dazhan_group_WS1810222337649') target_path = os.path.abspath(r'D:\Weekly_Refresh\needToCheck') if not os.path.exists(target_path): os.makedirs(target_path) if os.path.exists(source_path): # root 所指的是當前正在遍歷的這個文件夾的本身的地址 # dirs 是一個 list,內容是該文件夾中所有的目錄的名字(不包括子目錄) # files 同樣是 list, 內容是該文件夾中所有的文件(不包括子目錄) for root, dirs, files in os.walk(source_path): for file in files: src_file = os.path.join(root, file) shutil.copy(src_file, target_path) print(src_file) print('copy files finished!')
shutil
