-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
add exist_ok to shutil.copytree #65048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
it would be REALLY nice (and REALLY easy) to add a parameter: exist_ok and pass this to os.makedirs with the same parameter name so you can use copytree to append a src dir to an existing dst dir. |
Here is a patch that adds the option. I am not very familiar with the internals of shutil and os so I would recommend that someone else review it. I haven't added any tests. I can try to if anyone wants but I am not sure how long it will take me or if I will find the time any time soon. |
awesome, thanks so much!! |
Contrary to makedirs, there could be two interpretations for exist_ok in copytree: a) if a directory or file already exists in the destination, ignore it and go ahead b) only do that for directories. The proposed patch does b), but the cp tool does a). It’s not clear to me which is best. Can you start a discussion on the python-ideas mailing list? |
how about instead we rename the new parameter to dirs_exists_ok or something like that since the method already allows for existing files. |
I am not sure. I am not on the python-ideas mailing list, and I am not sure I can start the discussion if anyone specifically wants me to, but I don't On Fri, Mar 7, 2014 at 1:41 PM, Éric Araujo <report@bugs.python.org> wrote:
|
I personally dont think this is worth investing the time for a discussion.
|
Adding some core devs to get their opinion on this proposal. |
I don't know what "the method already allows for existing files" means. Since the target directory can't exist, there can be no existing files. In unix, this kind of capability is provided by a combination of shell globbing and 'cp -r', and by default it does replace existing files. So it would be reasonable for exists_ok to mean exactly that: replace anything that currently exists, if it does. I think that would be a reasonable API, but the implementation isn't as simple as just passing through the exists_ok flag to makedirs. I do not think that *just* making it OK for the destination directory to exist would be a good API. |
Ya. The original request I think is ok because by allowing that flag it
|
btw, I believe the solution is as simple as stated as that's what I'm doing locally and its behaving exactly as intended. |
I think this feature request is reasonable for 2 reasons:
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 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". |
I submitted a new PR in #8792 that addresses the outstanding concerns in @ofekmeister's original PR. It includes passing tests and passes all the GitHub PR status checks. Does it look ok to merge? Thanks. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: