function tryToChangeDirectory(newCWDPathInfo)
%TRYTOCHANGEDIRECTORY Attempts to change directory to the first entry in
% newCWDPathInfo.
%    If any errors are encountered whilst changing directory, the existing
%    CWD will remain and a warning will be issued.

% Copyright 2017-2020 The MathWorks, Inc.

pathToCd = parallel.internal.pool.WorkerPathHelper.getPathToCd(...
    newCWDPathInfo.RawPaths{1}, newCWDPathInfo.UNCPaths{1}, ...
    newCWDPathInfo.MATLABDrivePathMap);
dctSchedulerMessage(6, '- tryToChangeDirectory calling cd %s', pathToCd);
try
    cd(pathToCd);
catch err
    dctSchedulerMessage(1, 'Failed to cd to Error is:', err);
    if feature('hotlinks')
        batchLink = '<a href="matlab: helpPopup batch">batch</a>';
    else
        batchLink = 'batch';
    end
    parallel.internal.warningNoBackTrace(...
        message('parallel:convenience:BatchErrorSettingCurrentDirectory', ...
        pathToCd, pwd, batchLink));
end

end
