问题描述:
rst=shutil.copy("/users/pc/dana","/users/pc/dana")#文件夹不可以 print(rst)
--------------------------------------------------------------------------- PermissionError Traceback (most recent call last) <ipython-input-26-3de5e597126d> in <module> ----> 1 rst=shutil.copy("/users/pc/dana","/users/pc/dana") 2 print(rst) D:\anaconda\lib\shutil.py in copy(src, dst, follow_symlinks) 239 if os.path.isdir(dst): 240 dst = os.path.join(dst, os.path.basename(src)) --> 241 copyfile(src, dst, follow_symlinks=follow_symlinks) 242 copymode(src, dst, follow_symlinks=follow_symlinks) 243 return dst D:\anaconda\lib\shutil.py in copyfile(src, dst, follow_symlinks) 118 os.symlink(os.readlink(src), dst) 119 else: --> 120 with open(src, 'rb') as fsrc: 121 with open(dst, 'wb') as fdst: 122 copyfileobj(fsrc, fdst) PermissionError: [Errno 13] Permission denied: '/users/pc/dana'
问题解决:
在copy的命令中,不可以对文件夹进行操作,所以,我创建了dada.docx文件进行测试
1 rst=shutil.copy("C:/users/pc/dana/dana.docx","c:/users/pc/dana/dada.docx") 2 print(rst)
c:/users/pc/dana/dada.docx
1 rst=shutil.copy("/users/pc/dana/dana.docx","/users/pc/dana/nana.docx")#文件夹不可以 2 print(rst)
/users/pc/dana/nana.docx
均可以实现
注意事项:shutil.copy(路径1,路径2)路径1和路径2不可重复,路径2可以自己重新命名
结果文件: