Feb-10-2020, 04:51 PM
So I did the same, but it is a function that returns a list of files:
PS - I'm just learning Python as well, but I have 30+ years of coding behind me.
import os from typing import List FileList = List[str] def get_list_of_files(base_folder: str, files: FileList) -> None: with os.scandir(base_folder) as entries: for entry in entries: # Skip all hidden files and folders if entry.name.startswith('.'): continue qualified_name = os.path.join(base_folder, entry) # If it's a file we'll added it to the collection if entry.is_file(): files.append(qualified_name) elif entry.is_dir(): # If it's a folder then we'll process that as well get_list_of_files(os.path.join(base_folder, entry), files) files = [] base_folder = '/Users/<user>/Development' get_list_of_files(base_folder, files) for file in files: print(file)You pass it the base folder and an empty list and it will populate it for you.
PS - I'm just learning Python as well, but I have 30+ years of coding behind me.
There is no passion to be found playing small - in settling for a life that is less than the one you are capable of living.