File tree Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Original file line number Diff line number Diff line change 1- %% STEM file name without directory or suffix
1+ %% STEM base file name without directory or suffix
2+ % STEM Extracts the file name without directory or suffix from a path.
3+ % s = stem(p) returns the stem (base name) of the file specified by the path p.
4+ % leading dot filenames are allowed.
5+ %
6+ % Input:
7+ % p - Character vector or string scalar specifying the file path.
8+ %
9+ % Output:
10+ % s - Character vector or string scalar containing the file name without directory or suffix.
211
3- function st = stem(p )
4- arguments
5- p {mustBeTextScalar }
6- end
12+ function s = stem(p )
713
8- [~ , n , s ] = fileparts(p );
14+ p0 = asManyOfPattern(wildcardPattern + (" /" | filesep ));
15+ % p1 matches a file extension (e.g., '.txt') or the end of the string
16+ p1 = (" ." + alphanumericsPattern + textBoundary(' end' )) | textBoundary(' end' );
917
10- if strempty(n )
11- % leading dot filename
12- st = s ;
13- else
14- st = n ;
15- end
18+ s = extractBetween(p , p0 , p1 );
1619
17- end
20+ i = strempty(s );
21+ s(i ) = extractAfter(p(i ), p0 );
1822
19- % !assert(stem('/a/b.c'), 'b')
20- % !assert(stem("a/b/.c"), ".c")
23+ end
Original file line number Diff line number Diff line change 88{" a/b/c/" , " " }, ...
99{" a/b/c.txt" , " c" }, ...
1010{" a/b/c.txt.gz" , " c.txt" }, ...
11+ {" a/b/.c" , " .c" }, ...
1112{' a/b/.c' , ' .c' }, ...
1213{" " , " " }
1314}
You can’t perform that action at this time.
0 commit comments