I am new to programming and am trying to filter out all the files in a directory (= excluding the sub-directories) with Python 3.
My test directory contains 3 PDF files and 2 subfolders, which contain other files. I want to get a Python list containing only the 3 PDF files.
My code (apart from the necessary imports) currently looks like this:
folder_content = listdir(TESTDIRECTORY)
file_list = []
for item in folder_content:
if path.isfile(item):
file_list.append(item)
else:
pass
print(file_list)
Unfortunatelly this only gives me an empty list: []
Why?