Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through directory, delete

Tags:

python

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?

like image 348
Biker John Avatar asked Feb 06 '26 14:02

Biker John


1 Answers

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))
like image 132
inspectorG4dget Avatar answered Feb 09 '26 09:02

inspectorG4dget