def getnextfiles(directory, sensor=None, count=1):
 if (sensor is None):
  fmt = re.compile((FILEFORMAT % '[^\\.]*'))
 else:
  fmt = re.compile((FILEFORMAT % re.escape(sensor)))
 files = [fmt.match(f) for f in os.listdir(directory)]
 files = [f for f in files if (f is not None)]
 files.sort(key=(lambda x: map(int, x.groupdict()['datetime'].split('-'))))
 return [f for f in files[:count]]

def getnextfiles ( directory , sensor = None , count = 1 ) : if ( sensor is None ) : fmt = re . compile ( ( FILEFORMAT % '[^\\.]*' ) ) else : fmt = re . compile ( ( FILEFORMAT % re . escape ( sensor ) ) ) files = [ fmt . match ( f ) for f in os . listdir ( directory ) ] files = [ f for f in files if ( f is not None ) ] files . sort ( key = ( lambda x : map ( int , x . groupdict ( ) [ 'datetime' ] . split ( '-' ) ) ) ) return [ f for f in files [ : count ] ]
returns a list of maximum count filenames to process .