Python Forum
Fixing "PermissionError: [Errno 13] Permission denied"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fixing "PermissionError: [Errno 13] Permission denied"
#1
Hello, I'm trying to use Python to automate unzipping of multiple files in a folder. I already have a script that works and unzips my files. But it won't copy contents of the zip files which has subfolders. In order to be able to extract everything into one main folder (disregarding original subfolder structure) I have found this code chunk on stackexchange. A moderator reported that the code is working for him therefore I should be investigating something else, not the code itself.

import os
import shutil
import zipfile

my_dir = r"C:\Users\username\My_Dataset\new"
my_zip = r"C:\Users\username\My_Dataset"

with zipfile.ZipFile(my_zip) as zip_file:
    for member in zip_file.namelist():
        filename = os.path.basename(member)
        # skip directories
        if not filename:
            continue

        # copy file (taken from zipfile's extract)
source = zip_file.open(member)
target = open(os.path.join(my_dir, filename), "wb")
with source, target:
     shutil.copyfileobj(source, target)
Here is the Traceback I get:

Error:
Traceback (most recent call last): File "C:/Users/username/PycharmProjects/GeoPandas/mergeAnswer.py", line 8, in <module> with zipfile.ZipFile(my_zip) as zip_file: File "C:\Users\username\Anaconda3\envs\playground\lib\zipfile.py", line 1207, in __init__ self.fp = io.open(file, filemode) PermissionError: [Errno 13] Permission denied: 'C:\\Users\\username\\My_Dataset
The only thing that looks suspicious to me is the direction of the slashes on Traceback. Some of them are forwards slashes while some of them are backwards. Could it be related to that? I'm running this code in Windows and haven't tried on a mac or linux.

Would it be possible to get some suggestions in order to make this script work? I don't need to use this specific script, I'm just trying to unzip a lot of files (some are under subfolders some are not) into one main folder.

Thanks in advance!
Reply


Messages In This Thread
Fixing "PermissionError: [Errno 13] Permission denied" - by puredata - Feb-06-2020, 09:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Circumvent the "access denied" page? Pedroski55 7 273 Jun-15-2024, 06:25 AM
Last Post: Pedroski55
  The INSERT permission was denied on the object Steven5055 3 1,711 Jun-12-2024, 08:13 AM
Last Post: GregoryConley
  Delete file with read-only permission, but write permission to parent folder cubei 6 22,381 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  KivyMD android app - problem with permission polak7gt 0 382 Jan-18-2024, 01:27 PM
Last Post: polak7gt
  Potential Permission error on Mac OSX Catalina OWOLLC 1 884 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
  logging: change log file permission with RotatingFileHandler erg 0 1,213 Aug-09-2023, 01:24 PM
Last Post: erg
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 7 1,748 Sep-12-2022, 02:55 AM
Last Post: AlexPython
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,917 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Server Folder Error : WinError5 Access Denied fioranosnake 1 1,207 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Permission issue when using scapy jao 3 10,544 Feb-05-2022, 06:14 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020