This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: shutil.copytree makedirs exception
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4
Status: closed Resolution: duplicate
Dependencies: Superseder: add exist_ok to shutil.copytree
View: 20849
Assigned To: Nosy List: martin.panter, yuriy_levchenko
Priority: normal Keywords:

Created on 2015-03-11 10:41 by yuriy_levchenko, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg237858 - (view) Author: yuriy_levchenko (yuriy_levchenko) Date: 2015-03-11 10:41
We have a code:
    names = os.listdir(src)
    if ignore is not None:
        ignored_names = ignore(src, names)
        ignored_names = set()

    errors = []

But if I had created this folder. I have exception.

Maybe add "if"?

    if os.path.isdir(dst) is False:
msg237907 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-03-11 22:18
In case it’s not clear to others, the first bit of code is from the shutil.copytree() implementation at Lib/

The documentation currently says “The destination directory . . . must not already exist”. Yuriy seems to be proposing to make copytree() use the existing destination directory, and only create it if it does not already exist. Perhaps you might be interested in Issue 20849, which proposes passing the os.makedirs(exist_ok=...) flag through, which would allow this functionality in a backwards-compatible way.
msg237925 - (view) Author: yuriy_levchenko (yuriy_levchenko) Date: 2015-03-12 12:05
Thanks for the clarifications. Yes parameter will be a good solution!
Date User Action Args
2022-04-11 14:58:13adminsetgithub: 67826
2015-03-12 13:07:10r.david.murraysetstatus: open -> closed
superseder: add exist_ok to shutil.copytree
resolution: duplicate
stage: resolved
2015-03-12 12:19:57yuriy_levchenkosettype: behavior
2015-03-12 12:05:56yuriy_levchenkosetmessages: + msg237925
2015-03-11 22:18:53martin.pantersetnosy: + martin.panter
messages: + msg237907
2015-03-11 10:41:47yuriy_levchenkocreate