I am trying to extract the stem out of multiple file paths using pathlib and failing to do so.
Here is the code I tried:
base_path = Path(__file__).parent
paths = (base_path / "../dictionary/files/").glob('**/*')
files = [x for x in paths if x.is_file()]
for i in range(len(files)):
stem_name = files.stem[i]
Here is the error:
for i in range(len(files)):
TypeError: object of type 'generator' has no len()
I have text files with names as 1.txt, 2.txt, 3.txt
Expected:
1
2
3