I am using a function that returns a list of all files (full path for each of them) with the given extension in the given folder and all subfolders. As the process is quite long and user can get feeling that the app freezes, every 5 seconds I write to the output the name of the file the script is working on. The code below works fine. But I am sure it is not the most readable and effective way to write it. So I am eager for feedback and advice. Note: I tend to import as little modules as possible. os and time for this task is enough, I think.
import os import time def all_files_list(checkpath): '''Creates list of all files in subfolders of the given folder. Counts only .png''' lastTimer = time.time() result_list =  if checkpath: for root, dirs, files in os.walk(checkpath): for x in files: if x[-4:] == ".png": if time.time() - lastTimer2 > 5: lastTimer2 = time.time() print('Working on ' + os.path.join(root, x)) result_list.append(os.path.join(root, x)) return result_list
It creates a list of all files. Then depending on the task settings this list is filtered by specific parameters (i.e. by the language code in specific part of the path name). Then there are many options available of what can be done with the files. Copy in some structure, comparing the same files in the next folders, etc.