Skip to content

Commit 99c3499

Browse files
committed
canonical: use_java option (default true)
1 parent b48bf84 commit 99c3499

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

+stdlib/canonical.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function c = canonical(p, expand_tilde)
1+
function c = canonical(p, expand_tilde, use_java)
22
%% canonical(p)
33
% If exists, canonical absolute path is returned
44
% if path does not exist, normalized relative path is returned
@@ -18,6 +18,7 @@
1818
arguments
1919
p (1,1) string
2020
expand_tilde (1,1) logical=true
21+
use_java (1,1) logical = true
2122
end
2223

2324
if expand_tilde
@@ -32,7 +33,7 @@
3233
end
3334

3435
if ~stdlib.is_absolute(c)
35-
if isfile(c) || isfolder(c)
36+
if stdlib.exists(c)
3637
% workaround Java/Matlab limitations
3738
c = stdlib.join(pwd, c);
3839
else
@@ -43,10 +44,14 @@
4344
end
4445
end
4546

46-
% similar benchmark time as java method
47-
% REQUIRES path to exist, while java method does not.
48-
% c = builtin('_canonicalizepath', c);
47+
if use_java
48+
c = java.io.File(c).getCanonicalPath();
49+
else
50+
% similar benchmark time as java method
51+
% REQUIRES path to exist, while java method does not.
52+
c = builtin('_canonicalizepath', c);
53+
end
4954

50-
c = stdlib.posix(java.io.File(c).getCanonicalPath());
55+
c = stdlib.posix(c);
5156

5257
end % function

0 commit comments

Comments
 (0)