import os def show_all_files_directory(dir_path: str, search_endung: str = None, search_string: str = None) -> list: """ Returns a list of all files in the directory and its subdirectories. Parameters: dir_path (str): Path to the root directory. search_endung (str): Ending for the file names to be searched. Default is None. search_string (str): String to be searched in the file names. Default is None. Returns: list: List of full paths to all files matching the search criteria. """ # Check if dir_path is not empty and exists if not os.path.isdir(dir_path): print("Die angegebene Verzeichnispfad existiert nicht.") return [] all_files_path = [] for root_folder, dirs, files in os.walk(dir_path, topdown=False): for name in files: full_path = str(os.path.join(root_folder, name)) # If search_endung is specified if search_endung: if not full_path.endswith(search_endung): continue # If search_string is specified elif search_string: if full_path.find(search_string) == -1: continue all_files_path.append(full_path) print("Dateien:") for file in all_files_path: print(file) return all_files_path if __name__ == "__main__": test = show_all_files_directory(dir_path="/home/jonnybravo/Downloads", search_endung=".txt") print(test)