-1

Today I was working on a python script that will copy a folder in one directory and paste it in another directory.Everything was going fine but when I ran my code,It gives me an eror masseges like this:

Traceback (most recent call last):
  File "c:\Users\sudam\OneDrive\Desktop\programming\python\projects\file_syncer\syncer.py", line 9, in <module>
    shutil.copy(pearent_directry , moving_directry)
  File "C:\Users\sudam\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 417, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "C:\Users\sudam\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 254, in copyfile
    with open(src, 'rb') as fsrc:
PermissionError: [Errno 13] Permission denied: 'C:/Users/sudam/OneDrive/Documents/Rainmeter'

and here is my code:

print('file syncer version 1.0')
import shutil
from elevate import elevate
elevate()
pearent_directry = 'C:/Users/sudam/OneDrive/Documents/Rainmeter'
moving_directry = 'D:/sync'
shutil.copy(pearent_directry , moving_directry)
print('process has finished with error code:0')

any yes,I did use elevate to try to get admin rights but,It doesn't work either. Can somebody please help me out in solving this issue?

  • yes,It is being run in an admin terminal – sudam edirisinghe May 29 '22 at 15:47
  • Check if your Documents folder is under CFA & if so disable it for that folder: https://support.microsoft.com/en-us/windows/allow-an-app-to-access-controlled-folders-b5b6627a-b008-2ca2-7931-7e51e912b034 – rdas May 29 '22 at 15:58
  • that also does not work – sudam edirisinghe May 29 '22 at 16:08
  • The problem is **nothing to do with** admin rights. `shutil.copy` copies *files* and does *not* copy directories. `shutil.copytree` is needed to copy folder contents recursively. Please see the [documentation](https://docs.python.org/3/library/shutil.html#shutil.copytree). Voting to close as a typo. On Linux "everything is a file", but on Windows an existing folder cannot be replaced with a file of the same name (unless you explicitly delete the folder first). – Karl Knechtel May 29 '22 at 16:09
  • oh thanks man appriciate the help! – sudam edirisinghe May 29 '22 at 16:09

1 Answers1

0

Bro, it's easier to change the code to fix your problem.

from distutils.dir_util import copy_tree

    
a = "The path to the file"
b = "The path to the file"
copy_tree(a, b)
print("Process finished")

Also read the PEP8 documentation.

NOSIS
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 29 '22 at 16:55