我的代码用于查看文件夹并删除分辨率为1920×1080的图像的脚本.我遇到的问题是当我的代码运行时;
import os
from PIL import Image
while True:
img_dir = r"C:\Users\Harold\Google Drive\wallpapers"
for filename in os.listdir(img_dir):
filepath = os.path.join(img_dir, filename)
im = Image.open(filepath)
x, y = im.size
totalsize = x*y
if totalsize < 2073600:
os.remove(filepath)
我收到此错误消息:
Traceback (most recent call last):
File "C:\Users\Harold\Desktop\imagefilter.py", line 12, in
os.remove(filepath)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\Harold\\Google Drive\\wallpapers\\Car - ABT Audi RS6-R [OS] [1600x1060].jpg'
只是为了确认,Python是我计算机上运行的唯一程序.是什么导致了这个问题,我该如何解决?