[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-ideas
Subject:    [Python-ideas] Add copy to pathlib
From:       Todd <toddrjen () gmail ! com>
Date:       2022-10-18 19:45:54
Message-ID: CAFpSVpJPBfQAk1Nu=c03Om9dHNRJpLXopnPBTNr7oEu12QTTcw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Currently, pathlib supports pretty much all common filesystem operations.
You can create, move, and delete both files and directories. One big
omission is copying. You need shutil for that.

Whatever the original intent might have been behind pathlib, it is now
effectively the standard tool for filesystem operations. As such, excluding
copying alone from basic operations creates an unnecessary hurdle for
users. It also increases the difficulty of doing such operations since
there is no hint within the pathlib documentation on how to copy, new users
basically need to google it to find out.  That is fine for less common
operations, but far from ideal from a basic one like copying.

So I think it would make a lot of sense to include copying inside pathlib.
I propose adding a `copy` method to `pathlib.Path` (for concrete paths).

The specific call signature would be:

copy(dst, *, follow_symlinks=True, recursive=True, dir_exist_ok=True)

This will call `shutil.copytree` for directories if recursive is True, or
`copy2` if recursive if False. For files it will call `copy2` always.

An alternative would be to have separate `copy` and `copytree` methods, but
in most situations I think copying on directories would want copying a tree.

[Attachment #5 (text/html)]

<div dir="ltr">Currently, pathlib supports pretty much all common filesystem \
operations. You can create, move, and delete both files and directories. One big \
omission is copying. You need shutil for that.  <div><br></div><div>Whatever the \
original intent might have been behind pathlib, it is now effectively the standard \
tool for filesystem operations. As such, excluding copying alone from basic \
operations creates an unnecessary hurdle for users. It also increases the difficulty \
of doing such operations since there is no hint within the pathlib documentation on \
how to copy,  new users basically need to google it to find out.   That is fine for \
less common operations, but far from ideal from a basic one like \
copying.</div><div><br></div><div>So I think it would make a lot of sense to include \
copying inside pathlib. I propose adding a `copy` method to `pathlib.Path` (for \
concrete paths).<br></div><div><br></div><div>The specific call signature would \
be:</div><div><br></div><div>copy(dst, *, follow_symlinks=True, recursive=True, \
dir_exist_ok=True)</div><div><br></div><div>This will call `shutil.copytree` for \
directories if recursive is True, or `copy2` if recursive if False. For files it will \
call `copy2` always.</div><div><br></div><div>An alternative would be to have \
separate `copy` and `copytree` methods, but in most situations I think copying on \
directories would want copying a tree.</div><div><br></div></div>



_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CRI43C2RM4VUEZLM4E7UYMGLPN4LV7J4/
 Code of Conduct: http://python.org/psf/codeofconduct/



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic