We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eed2abd commit 21286aeCopy full SHA for 21286ae
+stdlib/filename.m
@@ -14,9 +14,21 @@
14
% because by our definition, a trailing directory component is not part of the filename
15
% this is like C++17 filesystem::path::filename
16
17
-parts = strsplit(stdlib.posix(p), '/');
+s = '/';
18
+if ispc()
19
+ s = '[/\\]';
20
+end
21
+
22
+f = char(p);
23
-f = parts{end};
24
+im = regexp(f, s, 'end');
25
+if ~isempty(im)
26
+ if im(end) == length(f)
27
+ f = '';
28
+ else
29
+ f = f(im(end)+1:end);
30
+ end
31
32
33
if isstring(p)
34
f = string(f);
test/TestFilename.m
@@ -5,7 +5,7 @@
5
{'', ''}, ...
6
{"", ""}, ...
7
{"/a/b/c", "c"}, ...
8
-{'/a/b/c/', ''}, ...
+{'/a/b/', ''}, ...
9
{'a/b/c.txt', 'c.txt'}, ...
10
{"a/b/c.txt.gz", "c.txt.gz"}, ...
11
};
0 commit comments