2

I want to copy folder from my local server on my computer, using function shutil.copytree, i using macOS, but today i have problem,python always show me the same message,"[error 1] operation not permitted",but yesterday mine script work without problems with same folders... Can someone tell me whats is the problem, what could have happened?

user1387805
  • 21
  • 1
  • 4

3 Answers3

2

The reason of 'operation not permitted' error can be the fact that shutil.copytree (as well as shutil.copy and shutil.copy2) has some weird behavior when the source and destination are on different filesystems.

E.g. I had problems with shutil.copy while trying to copy a file from ext3 to ntfs volume on ubuntu using python2.7. I've just used shutil.copyfile instead.

Speaking about shutil.copytree: take a look at this answer, I like it - just write your own copytree.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

You are trying to copy over an existing directory is my guess.

From the documentation

shutil.copytree = copytree(src, dst, symlinks=False, ignore=None) Recursively copy a directory tree using copy2().

The destination directory must not already exist.

Note that last line.

I don't have a MAC OS machine to verify, but I'm guessing that the destination directory exists. Here is what happens on my Linux machine which gives a similar error

$ mkdir test1
$ touch test1/a
$ touch test1/b

Then in the interactive interpreter

>>> from shutil import copytree
>>> copytree("test1","test2")
>>> copytree("test1","test2")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/shutil.py", line 175, in copytree
    os.makedirs(dst)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: 'test2'

Nick Craig-Wood
  • 52,955
  • 12
  • 126
  • 132
1

The error code is telling you that you don't have the permission to either read the source or write to the destination. Did the permission settings of your files and folders change?

Bernhard
  • 8,583
  • 4
  • 41
  • 42
  • Thank you Bernhard. No, the permission settings on my computer did not change, but maybe did on the server. I am not sure about that, I'll have to check it with my colleague who's responsible for the server. Thank you one more time! – user1387805 May 10 '12 at 18:47