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"
#9
(Feb-08-2020, 03:41 AM)TheHacker707 Wrote: If permission really is the problem, you could try to run the program with admin user level. Also, I would keep your slashes as backslashes if you're using Windows.
-707

Now I'm trying the same on a mac and don't get the permission error but I get this instead

Error:
self.fp = io.open(file, filemode) IsADirectoryError: [Errno 21] Is a directory: '/Users/berkaytok/Documents/Boundary_Datasets'
so I imagine stullis seems correct that this script expects a single zip file.

(Feb-06-2020, 11:41 PM)stullis Wrote: According to the docs, zipfile.ZipFile() expects a file, not a directory. I'd wager that's the culprit. Try creating the file first and passing that into zipfile.ZipFile().

Moving on to my previous script;

import os
import zipfile

user: str = os.getlogin() #to be used in directory names
#item = 'item'  # i am not sure if this is necessary
dir_name = "/Users/{0}//Documents/Boundary_Datasets".format(user) #folder that contains multiple zipfiles which some of them have subfolders in those zipfiles
extract = "/Users/{0}//Documents/Boundary_Datasets/new".format(user) #main folder to be used as an output folder
extension = ".zip" 
#file_name = dir_name + "/" + item #i am not sure if this is necessary

os.chdir(dir_name)  # change directory from working dir to dir with files

for item in os.listdir(dir_name):  # loop through items in dir
    if item.endswith(extension):  # check for ".zip" extension
        file_name = os.path.abspath(item)  # get full path of files
        zip_ref = zipfil e.ZipFile(file_name)  # create zipfile object
        zip_ref.extractall(extract)  # extract file to dir
        zip_ref.close()  # close file
        # os.remove(file_name) # delete zipped file
Can anyone help me to modify this so that it not only extracts the first subfolder content but all subfolders and extract all files into one main folder?
Reply


Messages In This Thread
RE: Fixing "PermissionError: [Errno 13] Permission denied" - by puredata - Feb-08-2020, 06:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Circumvent the "access denied" page? Pedroski55 7 272 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 883 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,206 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Permission issue when using scapy jao 3 10,542 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