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.
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)