我有一个文件夹与JFIF照片,我需要将它们全部转换成JPEG格式,我认为问题来自我的if语句,因为文件夹中有其他照片不需要转换或for循环。谢谢
from PIL import Image
import os
root = r"(my computer path to the folder)"
count = 0
for dirs, subdir, files in os.walk(root):
for file in files:
lastChar = file[-1:]
if(lastChar == 'f'):
img = Image.open(file)
#file ends in .jfif, remove 4 characters
fileName = file[:-4]
#add jpg and save
img.save(fileName + "jpg")我现在正在收到这个错误,FileNotFoundError: Errno 2没有这样的文件或目录:'IMG_4242_1615254307.jfif‘
发布于 2022-05-20 09:45:11
from PIL import Image
import os
root = r"my computer path to the folder"
print(root)
count = 0
for dirs, subdir, files in os.walk(root):
for file in files:
lastChar = file[-4:]
if(lastChar == 'jfif'):
img = Image.open(root+'\\'+file)
#file ends in .jfif, remove 4 characters
fileName = file[:-4]
print(fileName)
#add jpg and save
img.save(root+'\\'+fileName + "jpg")https://stackoverflow.com/questions/72190966
复制相似问题