将文件夹复制到上一级新文件夹中
我有一个文件夹(1.0),我想把它复制到上一级目录的文件夹里。举个例子: C:\Users\remco\Downloads\stikstof-master\1.0 我想把这个(1.0)文件夹或者里面的所有文件(总共20个文件)复制到: C:\Users\remco\Downloads\stikstof-master# 请注意,2.0这个文件夹现在还不存在。
我用下面的代码成功获取了当前文件的路径:
from utils import os
import shutil
file_path = os.getcwd()
print (file_path)
我尝试了一些在os和shutil这两个库里的方法,但就是没能搞定。
1 个回答
0
import shutil
source_path = r'C:\Users\remco\Downloads\stikstof-master\1.0'
destination_path = r'C:\Users\remco\Downloads\stikstof-master'
try:
shutil.copytree(source_path, destination_path, dirs_exist_ok=True)
except Exception as e:
print(f"Error occurred while copying directory: {e}")
当然可以!请把你想要翻译的内容发给我,我会帮你用简单易懂的方式解释清楚。