2016-02-19 41 views
0

我有一个与它的子目录结合2文件夹的问题,我有2个文件夹源。我把它命名为:test-2test-2和路径,以这些文件夹是output/test-2output/test-4结合2个目录与它的子目录

我这一行合并它:

merged_folder_path = 'merged/dir/output' 
shutil.copy(result_1_path, merged_folder_path) 
shutil.copy(result_2_path, merged_folder_path) 

但得到错误:

Traceback (most recent call last): 
    File "jamu.py", line 769, in <module> 
    main(sys.argv) 
    File "jamu.py", line 757, in main 
    shutil.copy(result_1_path, merged_folder_path) 
    File "C:\Python27\lib\shutil.py", line 119, in copy 
    copyfile(src, dst) 
    File "C:\Python27\lib\shutil.py", line 82, in copyfile 
    with open(src, 'rb') as fsrc: 
IOError: [Errno 13] Permission denied: 'output/test-2' 

是什么问题我的代码?前复制/移动

+2

这看起来不像Python问题。我怀疑你没有合适的权限来访问你正在移动的目录。如果您使用的是类似unix的系统,请尝试使用'chmod'更改权限。 – ChrisP

+0

我使用Windows的方式, 我有更改权限的目录和子目录与CACLS 与 'CACLS myfoldername/T/E/G所有人:F' 从[这个链接(https://开头的社区。 spiceworks.com/how_to/1638-using-cacls-to-modify-file-folder-permissions-for-users-groups-in-batch-file) 但它仍然不起作用。 – Densus

+0

可能的副本[复制目录到python目录的内容](http://stackoverflow.com/questions/15034151/copy-directory-contents-into-a-directory-with-python) – Oin

回答

0

我得到同样的问题here

它工作给我, 感谢所有的答案。 apreciated它!

0

检查烫发/删除

import os 
if os.access(merged_folder_path,os.W_OK): 
    shutil.copy(...,...) 
  • os.F_OK:路径是存在
  • os.R_OK:路径的可读性。
  • os.W_OK:路径的可写性。
  • os.X_OK路径可以执行。
+0

它仍然不工作:( – Densus