<分区> 分区>
我有一个关于在使用 python 将文件从 psd 转换为 jpg 后如何保存文件的问题。因为我想检查每个文件,所以我使用了 os.walk 函数。这是我的代码。 当我运行它时,出现了这个错误。
FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'test02.psd'
我要保存文件的文件夹与python文件属于同一类别。 但是 psd 文件位于某处的子文件夹中。
我怎样才能克服这个问题?
from PIL import Image
import os
for path, dir, files in os.walk('.'):
for file in files:
if file.endswith('.psd'):
print('The {} is being converted to jpg...'.format(file))
i = Image.open(file)
fn, fext = os.path.splitext(file)
try:
i.save('jpgs/{}.jpg'.format(fn)) # I created a folder named 'jpgs' already.
except Exception as e:
print(e)
