That is, instead of building a List]]], build a Dict].Ī single call to os.walk is sufficient to perform the job that yield_files_in_subfolders and yield_files_with_extensions are currently doing together. files=" + str(len(a)))Ī dictionary is the more appropriate data structure to use here, since your code is essentially building a mapping from directory paths to lists of matched filenames. If fnmatch.fnmatch(file.lower(),file_match.lower()):īreak # without this line it traverses the subfolders tooĭef yield_files_in_subfolders(folder_path, file_match): import osĭef yield_files_with_extensions(folder_path, file_match):įor root, dirs, files in os.walk(folder_path): So, I thought, why not give try Python a try ? The web page will eventually use javascript on the client-side for the user to choose a file from a list and "cast" it from the Pi4's apache2 web server over to the chromecast device. I hope to use the code to generate a nightly json file underpinning a chromecasting web server on a Raspberry Pi 4, based on Google's example chrome (web page) "sender". The python3 script below fetches a large list of matching files in a folder tree, in the format: ]īeing only a python newbie, there HAS to be a better way ? Still unsure of the python terminology at the moment :( I am an old python newbie here, migrating from fortran77 )
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |