Add one 'if' condition to ensure the first file of each dataset exists. If not, metadata is assigned to NULL.