Python Forum

Full Version: Copy and Paste Files - Command
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
One thing is sure, permission errors are not usually related to python. You may want to learn how to check file/folders owners and permissions on your system. Spot the file/folder which causes troubles and carefully examine who is the owner and what permissions there are.