将文件夹复制到方向上一级的新文件夹中

问题描述 投票:0回答:1

我有一个文件夹(1.0),我想将其复制到目录的上一级文件夹。 例如: C:\用户 emco\下载\stikstof-master .0 我想要将文件夹 (1.0) 或文件夹中的所有文件(20 个文件)复制到: C:\用户 emco\下载\stikstof-master# 请注意,2.0文件夹仍然不存在

我设法使用以下代码获取当前文件路径:

from utils import os
import shutil
file_path = os.getcwd()
print (file_path)

我在操作系统和shutil包中尝试了一些东西,但我就是无法让它工作。

提前致谢。

python directory operating-system 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}")
© www.soinside.com 2019 - 2024. All rights reserved.