Feb-08-2020, 06:54 AM
(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 fileCan 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?