'rb') as f: PermissionError: [Errno 13] Permission denied

577 views Asked by At

I've a problem with the copy file with a progress bar, i've this message error :

" File "C:\Users\Sn00f\PycharmProjects\MegaProjet\mesfonctions.py", line 261, in installdreamcast with open(src_pathdream, 'rb') as f: PermissionError: [Errno 13] Permission denied: 'C:\Users\Sn00f\Desktop\Dreamcast"

My code :

def installdreamcast():
src_pathdream = r'C:\Users\Sn00f\Desktop\Dreamcast'
fsize = int(os.path.getsize(src_pathdream))
dest_pathdream = r'C:\AppMetier\Deamcast'
with open(src_pathdream, 'rb') as f:
    with open(dest_pathdream, 'ab') as n:
        with tqdm(ncols=60, total=fsize, bar_format='{l_bar}{bar} | Remaining: {remaining}') as pbar:
            buffer = bytearray()
            while True:
                buf = f.read(8192)
                n.write(buf)
                if len(buf) == 0:
                    break
                buffer += buf
                pbar.update(len(buf))
print("It's GOOOOOOOOOOOOOOOOOOOOOOOOD")

How to resolve this "PermissionError: [Errno 13] Permission denied"

Thank you

1

There are 1 answers

0
LozzerJP On

Clearly, the file you are trying to access does not have read permissions. Why not remove the second and third with blocks and try to open a file that you know has read permissions to check that the first with block is working.