我的代码是用于查看一个文件夹并删除分辨率低于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 是我电脑上唯一运行的程序。这个问题是由什么引起的,我该怎么解决?
file_path = os.path.join(os.path.expanduser("~/Desktop"),'my_file.zip')
构建了一个路径,然后尝试执行file_path.close()
,就会出现 AttributeError: 'str' object has no attribute 'close' 的错误。 - Adrian Keister