【发布时间】:2015-01-28 16:41:04
【问题描述】:
我的代码用于查看文件夹并删除分辨率为 1920x1080 的图像的脚本。我遇到的问题是当我的代码运行时;
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 <module>
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 是我计算机上唯一运行的程序。是什么导致了这个问题,我该如何解决?
【问题讨论】:
标签: python python-3.x file-handling