function removeDirectory(dirName)
%removeDirectory Remove a directory with logging if it failed.

% Copyright 2014-2016 The MathWorks, Inc.

try
    if exist(dirName, 'dir') == 7
        % Remove directory and subdirectories from path before deleting to
        % avoid poor rmdir performance (see g1424958). Make sure to remove
        % only those folders and subfolders that are on the path to avoid
        % producing warnings from this operation.
        splitPath = @(pathStr) strsplit(pathStr, pathsep);
        foldersAndSubfoldersOnPath = strjoin(intersect(splitPath(genpath(dirName)), splitPath(path)), pathsep);
        rmpath(foldersAndSubfoldersOnPath);
        
        [success, message, ~] = rmdir(dirName, 's');
        dctSchedulerMessage(1, 'Removed %s with result: %d, message: %s', ...
                            dirName, success, message);
    end
catch e %#ok<NASGU> - Tell the user - but OK to continue
    dctSchedulerMessage(1, 'Unable to remove directory: %s', dirName)
end
end
