spm_rmpath.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function varargout = spm_rmpath(d)
  2. % Recursively removes SPM paths from the MATLAB path
  3. % SPM_RMPATH checks if the file spm.m is found and removes the
  4. % path to that file and any subdirectories below it from the MATLAB
  5. % path.
  6. %
  7. % P = SPM_RMPATH performs the same function as above and returns the
  8. % cleaned path string in P.
  9. %
  10. % SPM_RMPATH(D) strips the path string D from the MATLAB path.
  11. %
  12. % P = SPM_RMPATH(D) strips the path string D from the MATLAB path and
  13. % returns the cleaned path string in P.
  14. %
  15. % See also PATH, ADDPATH, RMPATH, GENPATH, PATHTOOL, SAVEPATH.
  16. %__________________________________________________________________________
  17. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  18. % Darren Gitelman & Guillaume Flandin
  19. % $Id: spm_rmpath.m 4025 2010-07-29 11:10:15Z guillaume $
  20. varargout = {};
  21. if ~nargin
  22. % Get the actual SPM directory
  23. try, d = spm('dir');
  24. catch, return; end
  25. end
  26. % Recursively remove directories in the MATLAB path
  27. p = textscan(path,'%s','delimiter',pathsep); p = p{1};
  28. i = strncmp(d,p,length(d)); P = p(i); p(i) = [];
  29. if ~nargin && ~isempty(P)
  30. fprintf('Removed %s paths starting from base path: "%s"\n',spm('ver','',1),d);
  31. elseif ~isempty(P)
  32. fprintf('Removed paths starting from base path: "%s" from:\n',d);
  33. else
  34. fprintf('No matching path strings found to remove\n')
  35. end
  36. if numel(P), fprintf('\t%s\n',P{:}); end
  37. % Set the new MATLAB path
  38. p = strcat(p,pathsep);
  39. path(strcat(p{:}));
  40. % Return the cleaned path if requested
  41. if nargout
  42. varargout{1} = p;
  43. end