I have a question about how to save files after I convert them from psd to jpg using python. Since I want to check every file, I used os.walk function. Here is my code. When I run this, I have this error.
FileNotFoundError: [Errno 2] No such file or directory: 'test02.psd'
The folder I want to save files in is in the same category as python file. But the psd file is in the subfolder somewhere.
How can I get over this?
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)