0
votes

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?

1
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
Yes I can. It seems shutil.copy only copies files but not folders. - alextc
what you are doing seems correct, you are copying file one by one into destination, try shutil.copytree(SOURCE_FOLDER, DESTINATION_FOLDER) - Skycc

1 Answers

1
votes

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