I'm struggling with opening one file at a time.
The most relevant post's solution either doesn't work for my case or I have not implemented it properly, as part of the below code.
I don't have these files or folders open anywhere else on my system. I am using Jupyter Notebooks
on Windows 10 Pro
.
pip3 install opendatasets
import opendatasets as od
import urllib
import zipfile
import os
import shutil
from PIL import Image
import time
try:
download = od.download('http://www.mae.cuhk.edu.hk/~cvl/iris_database/iris_database.zip', '../data/')
path_extract = '../data/iris_database/'
with zipfile.ZipFile('../data/iris_database.zip', 'r') as zip_ref:
zip_ref.extractall(path_extract)
#time.sleep(30)
os.remove(path_extract + 'readme.txt')
filenames = os.listdir(path_extract)
scans = []
for f in filenames:
#img = Image.open(path_extract + f)
with Image.open(path_extract + f) as img:
#print("IMG", img)
matrix = np.array(img)
#print("MATRIX", matrix)
scans.append(matrix)
print("before RMTREE")
shutil.rmtree(path_extract) # REMOVE LINE TO WORK
print("before OS.REMOVE")
os.remove(path_extract[:-1] + '.zip')
except (urllib.error.URLError, IOError, RuntimeError) as e:
print(e)
>>> [WinError 32] The process cannot access the file because it is being used by another process: '../data/iris_database/riris26.bmp'