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 22% get last part of directory path
33% if filename, return filename with suffix
44arguments
5- apath string
5+ apath ( 1 , : ) string
66end
77
8- k = strlength(apath ) == 0 ;
9- final(k ) = " " ;
8+ import stdlib.fileio.absolute_path
109
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 ));
1811
1912last = append(name , ext );
2013
Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ function test_posix(tc)
2525tc .verifyEmpty(posix(string .empty ))
2626end
2727
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+
2840function test_is_absolute_path(tc )
2941
3042import stdlib.fileio.is_absolute_path
You can’t perform that action at this time.
0 commit comments