Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

directory - Python: Error 13 Permission denied when using shutil.copy but no error for shutil.move

I am trying to copy all files and folders from one directory to another. If I run the following, it works fine with no error:

import shutil

input_path = r'C:DocumentsInput'
output_path = r'C:DocumentsOutput'

shutil.move(input_path, output_path)

This would be fine, except that I aim to keep the files in the input path as well. When I run shutil.copy(input_path, output_path), I end up getting PermissionError: [Errno 13] Permission denied: 'C:DocumentsInput'. Does anyone know why this might be? It seems odd that the .move works fine while the .copy gives me this error.

Traceback (most recent call last):
  File "C:AppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesIPythoncoreinteractiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-45-f4c01659b2b9>", line 1, in <module>
    shutil.copy(input_path, output_path)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0libshutil.py", line 415, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0libshutil.py", line 261, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:DocumentsInput'
question from:https://stackoverflow.com/questions/65926118/python-error-13-permission-denied-when-using-shutil-copy-but-no-error-for-shuti

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...