jgoenetxea
3/22/2019 - 11:16 AM

Read all files in folder by extension

from os import listdir
from os.path import isfile, join

def get_all_files_in_folder(folderPath: str, fileExtension: str):
    totalExtension = ''
    if fileExtension.startswith('.'):
        totalExtension = fileExtension
    else:
        totalExtension = '.' + fileExtension

    return [f for f in listdir(folderPath) if isfile(join(folderPath, f)) and f.endswith(totalExtension)]


def get_all_folders_in_folder(folderPath: str):
    return [f for f in listdir(folderPath) if not isfile(join(folderPath, f))]