# Copy and Paste Files - Command

**URL:** <https://discuss.python.org/t/copy-and-paste-files-command/56606>\
**Category:** Python Help\
**Created:** [June 24, 2024, 10:32pm UTC](https://discuss.python.org/t/copy-and-paste-files-command/56606 "2024-06-24T22:32:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MicheliBarcello](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@MicheliBarcello](https://discuss.python.org/u/MicheliBarcello)\
**Post date:** [June 24, 2024, 10:32pm UTC](https://discuss.python.org/t/copy-and-paste-files-command/56606/1 "2024-06-24T22:32:07Z")

</div>

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

```python
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

---

<div class="post-metadata">

**Author:** ![MicheliBarcello](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@MicheliBarcello](https://discuss.python.org/u/MicheliBarcello)\
**Post date:** [June 24, 2024, 11:03pm UTC](https://discuss.python.org/t/copy-and-paste-files-command/56606/2 "2024-06-24T23:03:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [June 24, 2024, 11:03pm UTC](https://discuss.python.org/t/copy-and-paste-files-command/56606/3 "2024-06-24T23:03:12Z")

</div>

> [@MicheliBarcello](#):
>
> `C:\Program Files`

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.

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [June 25, 2024, 9:52am UTC](https://discuss.python.org/t/copy-and-paste-files-command/56606/4 "2024-06-25T09:52:56Z")

</div>

> [@MicheliBarcello](#):
>
> I discovered that if I open VisualStudio with the right button and run it as administrator, this program works fine.

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.

> [@MicheliBarcello](#):
>
> The strange thing is that it was a .py file and it always worked, out of nowhere this afternoon this bug started

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.
