Copy and Paste Files - Command

Good night people,
I have a problem, I used the following code to copy and paste files from one folder to another

import os
import time
import shutil

origem = r"C:\Program Files\Corel\CorelDRAW Graphics Suite 2022\Programs64\Pasta2"
destino = r"C:\Program Files\Corel\CorelDRAW Graphics Suite 2022\Programs64\Pasta1"

def copy_files(origem, destino):
    os.makedirs(destino, exist_ok=True)
    for item in os.listdir(origem):
        origem_arquivo = os.path.join(origem, item)
        destino_arquivo = os.path.join(destino, item)
        if os.path.isfile(origem_arquivo):
            shutil.copy2(origem_arquivo, destino_arquivo)

copy_files(origem, destino)

but it started giving an error that I don’t have permission

It started out of nowhere, it always worked, but now this error has started.
I haven’t changed anything on my computer
Could you help me find why? Thanks

PermissionError: [Errno 13] Permission denied: 'C:\Program Files\Corel\CorelDRAW Graphics Suite 2022\Programs64.… I discovered that if I open VisualStudio with the right button and run it as administrator, this program works fine. The strange thing is that it was a .py file and it always worked, out of nowhere this afternoon this bug started

Try to paste a file there as a normal user in File Explorer. This is a protected directory.

Python does give you super powers, but it does not hack Windows and remove its security features by default.

Run your script as admin, or choose a non-protected path for the destination.

Check out pathlib by the way.

Yes, that’s because you need administrator permissions to change any files inside C:\Program Files. That’s just how Windows is set up. It helps limit the damage that malware could do if you got some on your computer.

It doesn’t matter what kind of file you copy, or that you have your code in a .py file. What matters is the directory where you want to make the new file. It worked before this afternoon, because you had administrator privileges when you ran the program before.