def files_in_dir(dirpath, wildcard="*", startpath=None):
    """
    Function generates list of files from specific dir

    files_in_dir(dirpath, wildcard="*.*", startpath=None)

    dirpath: required directory
    wilcard: mask for files
    startpath: start for relative path

    Example
    files_in_dir('medical/jatra-kiv','*.dcm', '~/data/')
    """

    import glob

    filelist = []

    if startpath is not None:
        completedirpath = os.path.join(startpath, dirpath)
    else:
        completedirpath = dirpath

    if os.path.exists(completedirpath):
        logger.info('completedirpath = ' + completedirpath)

    else:
        logger.error('Wrong path: ' + completedirpath)
        raise Exception('Wrong path : ' + completedirpath)

    for infile in glob.glob(os.path.join(completedirpath, wildcard)):
        filelist.append(infile)

    if len(filelist) == 0:
        logger.error('No required files in path: ' + completedirpath)
        raise Exception('No required file in path: ' + completedirpath)

    return filelist
def files_in_dir ( dirpath , wildcard = "*" , startpath = None ) : import glob filelist = [ ] if startpath is not None : completedirpath = os . path . join ( startpath , dirpath ) else : completedirpath = dirpath if os . path . exists ( completedirpath ) : logger . info ( 'completedirpath = ' + completedirpath ) else : logger . error ( 'Wrong path: ' + completedirpath ) raise Exception ( 'Wrong path : ' + completedirpath ) for infile in glob . glob ( os . path . join ( completedirpath , wildcard ) ) : filelist . append ( infile ) if len ( filelist ) == 0 : logger . error ( 'No required files in path: ' + completedirpath ) raise Exception ( 'No required file in path: ' + completedirpath ) return filelist
Function generates list of files from specific dir

    files_in_dir(dirpath, wildcard="*.*", startpath=None)

    dirpath: required directory
    wilcard: mask for files
    startpath: start for relative path

    Example
    files_in_dir('medical/jatra-kiv','*.dcm', '~/data/')