File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change 2
2
% get last part of directory path
3
3
% if filename, return filename with suffix
4
4
arguments
5
- apath string
5
+ apath ( 1 , : ) string
6
6
end
7
7
8
- k = strlength(apath ) == 0 ;
9
- final(k ) = " " ;
8
+ import stdlib.fileio.absolute_path
10
9
11
- final(~k ) = extractAfter(apath(~k ), strlength(apath(~k ))-1 );
12
-
13
- i = final == " /" | final == " \" ;
14
-
15
- apath(i ) = extractBefore(apath(i ), strlength(apath(i )));
16
-
17
- [~ , name , ext ] = fileparts(apath );
10
+ [~ , name , ext ] = fileparts(absolute_path(apath ));
18
11
19
12
last = append(name , ext );
20
13
Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ function test_posix(tc)
25
25
tc .verifyEmpty(posix(string .empty ))
26
26
end
27
27
28
+ function test_path_tail(tc )
29
+
30
+ import stdlib.fileio.path_tail
31
+
32
+ tc .verifyEqual(path_tail(" /foo/bar/baz" ), " baz" )
33
+ tc .verifyEqual(path_tail(" /foo/bar/baz/" ), " baz" )
34
+ tc .verifyEqual(path_tail(" /foo/bar/baz/." ), " baz" )
35
+ tc .verifyEqual(path_tail(" /foo/bar/baz/.." ), " bar" )
36
+ tc .verifyEqual(path_tail(" /foo/bar/baz.txt" ), " baz.txt" )
37
+
38
+ end
39
+
28
40
function test_is_absolute_path(tc )
29
41
30
42
import stdlib.fileio.is_absolute_path
You can’t perform that action at this time.
0 commit comments