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.

classification
Title: shutil.copytree() add a copy_func parameter.
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Allow choice of copy function in shutil.copytree
View: 1540112
Assigned To: tarek Nosy List: tarek, ysj.ray
Priority: normal Keywords:

Created on 2010-04-14 04:29 by ysj.ray, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg103111 - (view) Author: ysj.ray (ysj.ray) Date: 2010-04-14 04:29
The shutil.copytree() function copies the whole tree recursively, and copy one single regular file with copy2(). I hope it can be more powerful(), that is, allow specifying a customerized copy function, rather than copy2(). To be specific, add an optional keyword argument, named "copy_func" or something like, default to copy2.

It will be useful for doing some customerized filesystem tree copying.

For example, when writing something like the project install script, or update script, which need to ignore some file while copying the whole directory, or changing ".ini" file after copying, or rename the file name after copying. All the specific copy action can be done in our customerized copy function instead of copy2().

Is there anybody who has the same feature request? Or is there some other module already provides the same functionality?

If so, I can provide a patch for it.

Thanks!
msg103120 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2010-04-14 11:51
Have you seen the ignore option ?

You can use it to filter out some files.

See the doc and the examples in docs.python.org
msg103121 - (view) Author: ysj.ray (ysj.ray) Date: 2010-04-14 11:56
Thanks for your help!

I see the 'ignore' parameter, but I need not just ignore some file, but also treat some file totally differently, for example, changing file name, or replace some text in the destination file.
msg103713 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2010-04-20 14:17
I have just added this feature yesterday, see #1540112.

Thanks!
History
Date User Action Args
2022-04-11 14:56:59adminsetgithub: 52642
2010-04-20 14:17:28tareksetstatus: open -> closed
resolution: duplicate
superseder: Allow choice of copy function in shutil.copytree
messages: + msg103713
2010-04-14 11:56:55ysj.raysetmessages: + msg103121
2010-04-14 11:51:32tareksetassignee: tarek
messages: + msg103120
2010-04-14 11:48:54r.david.murraysetpriority: normal
nosy: + tarek
2010-04-14 04:29:26ysj.raycreate