I'm working on a folder with 150 thousand files (~64 kb size each) stored on my Google Drive. In Google Colab, I'm using the following function to get the list of all files. Colab throws the drive timeout error when I ran the function on the folder with 150k files. I tried remounting the drive multiple times, restarting Colab, and using glob to obtain the list of files. None of these approaches worked for me.
Do you know how I can effectively work with 150k files?
def list_all_files_with_an_extension(pth_folder: str, file_extension: list = [".png"]) -> list:
"""
Get files from a folder with an extension
"""
# Placeholder
list_files = []
# Walk through dir and sub dire
for root, dirs, files in os.walk(pth_folder):
for file in files:
for extension in file_extension:
if file.endswith(extension):
list_files.append(os.path.join(root, file))
# Return the list of paths
return list_files