import os
src_path=r'E:\Pycharm\python100题\代码'
target_path=r'E:\Pycharm\python100题\123'
def copy_function(src,target):
if os.path.isdir(src) and os.path.isdir(target):
filelist=os.listdir(src)
for file in filelist:
path=os.path.join(src,file)
if os.path.isdir(path):
copy_function(path,target)
with open(path,'rb') as rstream:
container=rstream.read()
path1=os.path.join(target,file)
with open(path1,'wb') as wstream:
wstream.write(container)
else:
print('复制完毕!')
copy_function(src_path,target_path)
import os
src_path=r'E:\Pycharm\python100题\代码'
target_path=r'E:\Pycharm\python100题\123'
def copy_function(src,target):
if os.path.isdir(src) and os.path.isdir(target):
filelist=os.listdir(src)
for file in filelist:
path=os.path.join(src,file)
if os.path.isdir(path):
target1=os.path.join(target,file)
os.mkdir(target1)
copy_function(path,target1)
else:
with open(path, 'rb') as rstream:
container = rstream.read()
path1 = os.path.join(target, file)
with open(path1, 'wb') as wstream:
wstream.write(container)
else:
print('复制完毕!')
copy_function(src_path, target_path)