0

i have a problem with combining 2 folder with it subdirectories, i have 2 folder source. i named it : test-2 and test-2 and path to these folder is output/test-2 and output/test-4

i combined it with this line:

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

but it get error:

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'

is something wrong with my code?

Densus
  • 21
  • 1
  • 7
  • 2
    This doesn't look like a Python problem. I suspect you don't have suitable permissions to access the directories you are moving. If you're on a unix-like system, try changing the permissions with `chmod`. – ChrisP Feb 19 '16 at 16:26
  • i use windows by the way, i have change permissions the directories and subdirectories with cacls with `cacls myfoldername /t /e /g everyone:f` from [this link](https://community.spiceworks.com/how_to/1638-using-cacls-to-modify-file-folder-permissions-for-users-groups-in-batch-file) but it's still doesn't work. – Densus Feb 20 '16 at 14:33
  • Possible duplicate of [Copy directory contents into a directory with python](http://stackoverflow.com/questions/15034151/copy-directory-contents-into-a-directory-with-python) – Oin Feb 20 '16 at 15:32
  • yes oin, i found a solution from that link too. thanks – Densus Feb 22 '16 at 03:47

2 Answers2

1

i get the same problem here.

and it's working to me, thanks for all the answers. apreciated it!

Community
  • 1
  • 1
Densus
  • 21
  • 1
  • 7
0

Check perms before copy/move/delete

import os
if os.access(merged_folder_path,os.W_OK):
    shutil.copy(...,...)
  • os.F_OK: path is exists
  • os.R_OK: readability of path.
  • os.W_OK: writability of path.
  • os.X_OK path can be executed.
Accex
  • 351
  • 1
  • 2
  • 11