os.walk不保存子目录中的图像

时间:2018-01-23 15:40:30

标签: python python-3.x python-imaging-library os.walk

Images是一个文件夹,其中包含10个子文件夹,每个子文件夹都有一个图像,我正在调整大小并保存在同一个地方,但os.walk无效,任何人都可以检查我做错了什么。

path='E:/Dataset_Final/Images/'
def count_em(path):
    for root, dirs, files in sorted(os.walk(path)):
        for file_ in files:
            full_file_path = os.path.join(root, file_)
            print (full_file_path)
            img = Image.open(full_file_path)
            new_width  = 32
            new_height = 32
            img = img.resize((new_width, new_height), Image.ANTIALIAS)
            img.save(os.path.join(root, file_+''),'png')
        return 
count_em(path)

1 个答案:

答案 0 :(得分:1)

return在第一个目录之后。

删除return语句,您的代码应按预期工作。

相关问题