[issue20849] add exist_ok to shutil.copytree

Giampaolo Rodola' report at bugs.python.org
Thu Aug 16 18:22:20 EDT 2018


Giampaolo Rodola' <g.rodola at gmail.com> added the comment:

I think this feature request is reasonable for 2 reasons:

1) As it stands if dst directory exists copytree() cannot be used. The only possible workaround is using rmtree(dst) first, but that doesn't seem to make much sense. The change may look extremely easy but the fact that copytree() cannot be used in a specific circumstance justifies the cost of introducing a new argument, basically because there is no other way around it.

2) "cp -r" does this by default, which is probably indicative (I don't think the default should be True though).

I think the new argument should be called "dirs_exists_ok" instead of "exists_ok" though, so that it's clear that the behavior does not affect files.

[ R. David Murray ]
> I do not think that *just* making it OK for the destination directory to exist would be a good API.

I don't think that refusing (or allowing) to copy existing files is a common enough use case to justify the addition of a new parameter (note: also "cp" does not provide this use case). If such a  behavior is desired the user can simply provide its own custom "copy_function".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue20849>
_______________________________________


More information about the Python-bugs-list mailing list