将一个文件夹内的所有文件遍历的复制到另一个文件夹中
def backup_file(path, path_two):
"""
:param path: 路径1
:param path_two: 路径2
:return:
"""
if os.path.isdir(path) and os.path.isdir(path_two): # 判断传入的值为文件夹
a = os.listdir(path) # 读取该路径下的文件为列表
for i in a:
po = os.path.join(path, i) # 路径1拼接
po_two = os.path.join(path_two, i) # 路径2拼接
with open(po, "rb") as f:
res_one = f.read()
with open(po_two, "wb") as a:
a.write(res_one)
print("{}复制成功".format(i))
else:
print("不是文件夹")