简体   繁体   English

错误 13 权限被拒绝

[英]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.我正在尝试 os.walk() 一个文件树,将一组文件复制到每个目录。 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?单个文件似乎可以复制(至少第一次迭代),但在尝试复制文件夹 (.images) 及其内容时抛出错误(IOError: [Errno 13] Permission denied: 'S:/NoahFolder\\.images') ? 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)

shutil.copy will only copy files, not directories. shutil.copy只会复制文件,而不是目录。 Consider using shutil.copytree instead, that's what it was designed for.考虑使用shutil.copytree ,这就是它的设计目的。

This implementation of copytree seemed to get it done! copytree 的这个实现似乎完成了! Thanks for the input @ holdenweb感谢您的输入@holdenweb

from distutils.dir_util import copy_tree

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

    for item in src_files:
        try:
          shutil.copy(item, path)
        except:
            print item
            print path
            copy_tree(dir_src, path)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM