I am trying to list (let's say) PDF files in a directory (to a GUI). I know I can manage that with in different ways (like below) but I also want the list is to be current and dynamic. For instance, if someone deletes a PDF file from or adds a PDF file to the directory, I want the application to delete or add the file name to the list instantly, without any refresh.
Do you know any ways to manage that?
Here is some of my code:
import os
pdffiles = [name for name in os.listdir('somedir')
if name.endswith('.pdf')]
for file in pdffiles:
print(file)
I am in a learning progress.