Python shutil.copytree - ignore permissions

Python is shutil.copytreenot very flexible; what is the easiest way to add support for ignoring permissions when copying to copytree(without having to re-write its implementation)?

Otherwise, copytreeterminates as follows:

(…)"[Errno 45] Operation not supported: ‘/path/foo/bar’"
+5
source share
2 answers

Do you have shutil.pyPython in your standard distribution kit (for example, in Ubuntu, my under /usr/lib/python2.6, maybe Windows C:\Python26\lib?). The copytree function has a length of only 38 lines (34 if you do not consider comments), and the end of the docstring explicitly indicates:

XXX Consider this example code rather than the ultimate tool.

, / copytree , .

+3

( ), script:

import shutil

_orig_copystat = shutil.copystat
shutil.copystat = lambda x, y: x

shutil.copytree(src, dst)

shutil.copystat = _orig_copystat
+2

All Articles