Skip to content

Commit f2db954

Browse files
committed
add filename()
1 parent d935cdf commit f2db954

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

+stdlib/+fileio/filename.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function p = filename(path)
2+
% FILENAME filename (including suffix) without directory
3+
arguments
4+
path string
5+
end
6+
7+
[~, n, e] = fileparts(path);
8+
9+
p = n + e;
10+
11+
end

+stdlib/+test/TestFilePure.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ function test_posix(tc)
1414
end
1515

1616

17+
function test_filename(tc)
18+
19+
tc.verifyEmpty(stdlib.fileio.filename(string.empty))
20+
tc.verifyEqual(stdlib.fileio.filename(""), "")
21+
22+
tc.verifyEqual(stdlib.fileio.filename("/foo/bar/baz"), "baz")
23+
tc.verifyEqual(stdlib.fileio.filename("/foo/bar/baz/"), "")
24+
25+
tc.verifyEqual(stdlib.fileio.filename("foo/bar/baz.txt"), "baz.txt")
26+
tc.verifyEqual(stdlib.fileio.filename("foo/bar/baz.txt.gz"), "baz.txt.gz")
27+
28+
end
29+
30+
1731
function test_parent(tc)
1832

1933
tc.verifyEmpty(stdlib.fileio.parent(string.empty))

+stdlib/filename.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function p = filename(path)
2+
% FILENAME filename (including suffix) without directory
3+
arguments
4+
path string
5+
end
6+
7+
p = stdlib.fileio.filename(path);
8+
9+
end

0 commit comments

Comments
 (0)