Reputation: 2711
I would like to loop through the given directory e://www/files/delivery
and all its subdirectories and delete all images that end with _thumb.jpg
.
What i have tried so far:
import os
dir='e:\www\files\delivery'
for root, dirs, files in os.walk(dir):
for name in files:
if name.endswith(("_thumb.jpg")):
os.remove(name?)....
Apparently this does not work.
Also, if i alternatively want to resize all images using python wand library
instead of deleting them, would it be the same process?
Upvotes: 3
Views: 5212
Reputation: 114035
import os
dir='e:\www\files\delivery'
for root, dirs, files in os.walk(dir):
for name in files:
if name.endswith(("_thumb.jpg")):
os.remove(os.path.join(root, name))
Upvotes: 8