folderName = 'c:\Program Files\Mobility Lab\workspace\MobilityLabProject\monitorData';
fileNames = dir([folderName '/*.h5']);

oldLabels = {'Left Foot','Right Foot'};
newLabels = {'Left Leg','Right Leg'};

newLabelList = {};
if length(fileNames) == 0
    error(['No files found at ' folderName]);
end

newLabelList = {};
for iFile = 1:length(fileNames)
    
    fileName = [folderName '/' fileNames(iFile).name];
    
    monitorCaseIDList = hdf5read(fileName, '/', 'CaseIdList');
    monitorLabelList = hdf5read(fileName, '/', 'MonitorLabelList');
    
    oldLabelList = {};
    for iMonitor = 1:length(monitorCaseIDList)
        monitorLabel = monitorLabelList(iMonitor).data;
        iLabel = strmatch(monitorLabel, oldLabels);
        if isempty(iLabel)
            newLabelList{iMonitor} = monitorLabel;
        else
            newLabelList{iMonitor} = newLabels{iLabel};
        end
        oldLabelList{iMonitor} = monitorLabel;
    end
    
    fileID = H5F.open(fileName,'H5F_ACC_RDWR','H5P_DEFAULT');
    fileIDCleanUp = onCleanup(@()H5F.close(fileID));
    % Open the dataset/group
    locID  = H5O.open(fileID, '/','H5P_DEFAULT');
    locIDCleanUp = onCleanup(@()H5O.close(locID));
    %open the attribute.
    attID = H5A.open(locID, 'MonitorLabelList', 'H5P_DEFAULT');
    H5A.close(attID);
    H5A.delete(locID, 'MonitorLabelList');
    
    details.AttachedTo = '/';
    details.AttachType = 'group';
    details.Name = 'MonitorLabelList';
    hdf5write(fileName, details, newLabelList, 'WriteMode', 'append');
    display(['Done processing file: ' fileName]);
end