I would like t write the script where all zip files in the folder would be extracted in another folder. I found a helpful answer here: Unzip all zipped files in a folder to that same folder using Python 2.7.5
I slightly edited the code from the answers there as listed down below
import zipfile36 as zipfile
working_dir = r"C:\Users\Tim\Desktop\Tim\Faks\NMG\Python\Python Scripting for Geoprocessing Workflows\PythonGP\PythonGP\Scripts" ###### LAHKO MENJAŠ POT ######
goal_dir= r"C:\Users\Tim\Desktop\Tim\Faks\NMG\Python\Python Scripting for Geoprocessing Workflows\PythonGP\PythonGP\Scripts\Ekstrahirano"
extension = ".zip"
for item in os.listdir(working_dir): # 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 = zipfile.ZipFile(file_name) # create zipfile object
zip_ref.extractall(goal_dir) # extract file to dir
zip_ref.close() # close file
os.remove(file_name) # delete zipped file
When running, I am constantly receiving this error
Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\IPython\core\interactiveshell.py", line 3437, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-98-d46cd220b77f>", line 8, in <module>
zip_ref = zipfile.ZipFile(file_name) # create zipfile object
File "C:\Users\Tim\AppData\Roaming\Python\Python39\site-packages\zipfile36.py", line 1100, in __init__
self._RealGetContents()
File "C:\Users\Tim\AppData\Roaming\Python\Python39\site-packages\zipfile36.py", line 1167, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile36.BadZipFile: File is not a zip file
What am I missing?