Search code examples
pythongloberrnoshutil

How to resolve Errno 13 Permission Denied


I have researched the similarly asked questions without prevail. I am trying to os.walk() a file tree copying a set of files to each directory. Individual files seem to copy ok (1st iteration atleast), but an error is thrown (IOError: [Errno 13] Permission denied: 'S:/NoahFolder\.images') while trying to copy a folder (.images) and its contents? I have full permissions to this folder (I believe).

What gives?

import os
import shutil
import glob

dir_src = r'S:/NoahFolder/.*'
dir_dst = r'E:/Easements/Lynn'
src_files = glob.glob(dir_src)
print src_files

for path,dirname,files in os.walk(dir_dst):
    for item in src_files:
        print path
        print item

        shutil.copy(item, path)

Solution

  • shutil.copy will only copy files, not directories. Consider using shutil.copytree instead, that's what it was designed for.