File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ function p = parent(path )
2
+ % PARENT parent directory of path
3
+ arguments
4
+ path string
5
+ end
6
+
7
+ % must drop trailing slash - need to as_posix for windows
8
+ p = fileparts(strip(stdlib .fileio .posix(path ), ' right' , ' /' ));
9
+
10
+ end
Original file line number Diff line number Diff line change @@ -14,6 +14,19 @@ function test_posix(tc)
14
14
end
15
15
16
16
17
+ function test_parent(tc )
18
+
19
+ tc .assertEmpty(stdlib .fileio .parent(string .empty ))
20
+ tc .verifyEqual(stdlib .fileio .parent(" " ), " " )
21
+
22
+ tc .verifyEqual(stdlib .fileio .parent(" /foo/bar/baz" ), " /foo/bar" )
23
+ tc .verifyEqual(stdlib .fileio .parent(" /foo/bar/baz/" ), " /foo/bar" )
24
+
25
+ tc .verifyEqual(stdlib .fileio .parent(" foo/bar/baz/" ), " foo/bar" )
26
+
27
+ end
28
+
29
+
17
30
function test_path_tail(tc )
18
31
19
32
import stdlib.path_tail
Original file line number Diff line number Diff line change
1
+ function p = parent(path )
2
+ % PARENT parent of path
3
+ arguments
4
+ path string
5
+ end
6
+
7
+ p = stdlib .fileio .parent(path );
8
+
9
+ end
You can’t perform that action at this time.
0 commit comments