function setRootFolder(h, startFolder)
%setRootFolder sets the folder corresponding to the $(START_DIR)

%   Copyright 2019-2020 The MathWorks, Inc.

% Canonicalize the path (this function errors if the path does not exist)
if ~isempty(startFolder)
    startFolder = builtin('_canonicalizepath', startFolder);
end

oldRootFolder = h.Settings.LocalAnchorDir;

if ~isempty(oldRootFolder)
    % Convert all the existing tokenized paths to full paths
    h.replacePathString('$(START_DIR)', oldRootFolder);
end

% Set the start folder
h.Settings.LocalAnchorDir = startFolder;

% Update all paths that use the new start dir
if ~isempty(startFolder)
    replacePathString(h, startFolder, '$(START_DIR)');
end
