0

I have a source folder which contains both a couple of sub-folders (containing files as well) and a number of files.

-SOURCE_FOLDER
    -Sub_Folder_A
        -File_AA
        -File_AB
        - ...
        - ...
    -Sub_Folder_B
        -File_BA
        -File_BB
        - ...
        - ...
    -FILE_A
    -FILE_B
    - ...
    - ...

The destination folder I would like to copy the content of the source folder to is already existing.

-DESTINATION_FOLDER

The code as below gave me IOError: [Errno 13] Permission denied:.

for outputFile in SOURCE_FOLDER:
    shutil.copy(outputFile, DESTINATION_FOLDER)

How can I achieve folder and file copy by shutil?

alextc
  • 3,206
  • 10
  • 63
  • 107
  • Well looks like the problem is not how to use shutil, but that you don't have permission... Can you do the copy manually? – Julien Nov 22 '17 at 00:38
  • Yes I can. It seems shutil.copy only copies files but not folders. – alextc Nov 22 '17 at 00:43
  • what you are doing seems correct, you are copying file one by one into destination, try `shutil.copytree(SOURCE_FOLDER, DESTINATION_FOLDER)` – Skycc Nov 22 '17 at 00:44

1 Answers1

1

The error that you're getting is because the program doesn't have permissions to that folder. Once you change the permissions you can try:

from distutils.dir_util import copy_tree
copy_tree(SOURCE_FOLDER, DESTINATION_FOLDER)

as mentioned here: Copy directory contents into a directory with python