I have a folder in my computer with many
file_one.txt --> location = r'C:\Users\User\data\file_one.txt'
file_two.txt --> location = r'C:\Users\User\data\file_two.txt'
file_forty.txt --> location = r'C:\Users\User\data\file_forty.txt'
list_from_files = ['file_one', 'file_two', 'file_forty']
You could use
pathlib1. It has a dedicated
stem property which returns the filename without suffix:
import pathlib p = pathlib.Path('.') # current directory, insert your directory here [x.stem for x in p.glob('*.txt')]