IOError: [Errno 2] No such file or directory – os.walk

前端 未结 1 1706
失恋的感觉
失恋的感觉 2020-12-12 04:37

I\'m trying to run the following script which simply reads and image and saves it again:

from PIL import Image
import os

rootdir = \'/home/user/Desktop/samp         


        
相关标签:
1条回答
  • 2020-12-12 05:34

    You're going to need to provide a fully qualified path, because file holds only the tail, not the entire path.

    You can use os.path.join to join the root to the tail:

    for root, dirs, files in os.walk(rootdir):
        for file in files:
            path = os.path.join(root, file)
            im = Image.open(path)
            im.save(path)
    
    0 讨论(0)
提交回复
热议问题