【问题标题】:Using shutil library to copy contents of a directory from src to dst, but not the directory itself使用shutil库将目录的内容从src复制到dst,但不复制目录本身
【发布时间】:2018-02-24 23:32:12
【问题描述】:

所以我有一个名为 /src 的目录,里面有几个内容:

a.png、file.text、/sub_dir1、/sub_dir2

我想将这些内容复制到目标目录 /dst 中,使 /dst 的内部看起来像这样(假设 /dst 之前是空的):

a.png、file.text、/sub_dir1、/sub_dir2

我已经尝试过 shutil.copytree(src, dst),但是当我打开 /dst 时,我看到了:

/src

虽然包含我想要的一切,但不应该在那里,因为我不想复制 /src 目录本身,只复制它的内部内容。有谁知道怎么做?

【问题讨论】:

    标签: python directory shutil copytree


    【解决方案1】:

    我在 copytree 函数中输入的文件路径有误。该功能按预期工作,正如我在问题中提到的那样。

    【讨论】:

      猜你喜欢
      • 2013-12-16
      • 2018-07-24
      • 2012-07-24
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2016-01-19
      相关资源
      最近更新 更多