-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenpath2.m
37 lines (31 loc) · 1.01 KB
/
genpath2.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
function p = genpath2(d, pattern)
%GENPATH2 calls genpath and removes folders matching a specified pattern
%
% INPUTS:
% d ~ char, the name of of the base folder
% pattern ~ char/cell, the starting folder pattern to exclude
%
% OUTPUTS:
% p ~ char, the cleaned path
%
% USAGE:
% genpath2(folderName) returns an array identical to genpath(folderName)
% genpath2(folderName, '.git') returns a array without folders starting with .git
% genpath2(folderName, {'.git', '.svn'}) returns a vector without folders starting with .git or .svn
%
% Santiago I. Sordo-Palacios, 2019
% Call MATLAB's genpath()
p = genpath(d);
% Return if missing or empty input argument
if nargin < 2 || isempty(pattern)
return
end
% Find folders that match the pattern
splitP = split(p, pathsep);
pattern = strcat(filesep, pattern);
hasPattern = contains(splitP, pattern);
% Index out folders with pattern
cleanP = splitP(~hasPattern);
% Return as list in genpath format
p = char(strjoin(cleanP, pathsep));
end % function-genpath2