0

I'm trying to print the stem-only of each file in a glob list. The filenames are the names of people so I would like to just display their names without full path and extension. Any suggestions? I have looked at os.path but the pathlib.stem seemed the cleanest.

    def listknownfaces(self, instance):
        faceslist = glob.glob('Event_Faces/*.jpg')
        print(faceslist)
        for one_item in faceslist.glob('*.jpg'):
            print(one_item.stem)

Thanks in advance.

ThomasATU
  • 572
  • 1
  • 5
  • 15

1 Answers1

1

Use pathlib to glob and then get the stem. pathlib.Path.stem gives you the name of the file without the extension.

from pathlib import Path

p = Path("Event_Faces")
for path in p.glob("*.jpg"):
    print(path.stem)
jkr
  • 17,119
  • 2
  • 42
  • 68