#!/usr/bin/env python
# -*- coding: cp936 -*-
#print "hello"
import os
import time
from collections import deque
sPh=r"D:\b"
tPh=r"D:\a"
def getDirAndCopyFile(sourcePath,targetPath):
if not os.path.exists(sourcePath):
return
#abstargetPath=r"D:\a"
#遍历文件夹
for fileName in os.listdir(sourcePath):
absourcePath = os.path.join(sourcePath,fileName)
#abstargetPath = os.path.join(targetPath, fileName)
if os.path.isdir(absourcePath):
getDirAndCopyFile(absourcePath,abstargetPath)
if os.path.isfile(absourcePath):
递归复制所有文件至同一目录
于 2019-03-04 09:15:46 首次发布
这是一个使用Python实现的脚本,用于从指定源路径递归地复制所有文件到目标路径。脚本首先检查源路径是否存在,然后遍历源路径中的每个文件和子目录。对于每个文件,它打开读取文件并写入目标路径,确保内容被完整复制。对于子目录,脚本会递归调用自身进行复制。最后,脚本计算并打印出整个复制过程的总耗时。
摘要由CSDN通过智能技术生成