-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpip_cleanMatlabpath.m
56 lines (47 loc) · 1.8 KB
/
pip_cleanMatlabpath.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function pip_cleanMatlabpath(tmp_workspace)
% Clean up Matlab by remove path's from the Matlab path if the path exist.
% Note: Do not remove path for actual function!
%
% Input:
% tmp_workspace{:}: Struct containing paths to be removed from Matlab path
% tmp_workspace : String containing one path to be removed from Matlab path
%
% Output:
%
% Uses:
%
%____________________________________________
%SW version: 261103TD, By T. Dyrby, 261103,DRCMR
%
%Only one path is given?
if(isstr(tmp_workspace))
tmp_workspace={tmp_workspace};
end
if(~isempty(tmp_workspace))
for(i=1:length(tmp_workspace))%NOTE: first dir is not removed is system dir
% %Ensure to get only path --- NO this removes the last dir in path!
% tmp_workspace{i}=fileparts(tmp_workspace{i});
while strcmp(tmp_workspace{i}(end),filesep) %Added by Thomas Rask 281103
tmp_workspace{i}=tmp_workspace{i}(1:(end-1));
end
if(strcmp(tmp_workspace{i},fileparts(which('pip_cleanMatlabpath'))))
%disp('Do not remove path for function')
continue
end
%ONLY FOR TEST
%(tmp_workspace{i})
%exist(tmp_workspace{i})
%Clean up Matlab path
if(isunix)%OS difference
tmp_pathSep=':';
tmp_path=[tmp_pathSep,path,tmp_pathSep];
else
tmp_pathSep=';';
tmp_workspace{i}=lower(tmp_workspace{i});%needs lower() because windows write path in lower. 281103TR
tmp_path=lower([tmp_pathSep,path,tmp_pathSep]);
end
if(~isempty(strfind([tmp_pathSep,tmp_workspace{i},tmp_pathSep],tmp_path)))
rmpath(tmp_workspace{i});%Clean-up Matlab path for old paths
end
end
end