1- function c = resolve(p , expand_tilde )
2- %% resolve(p)
3- % path need not exist--absolute path will be relative to pwd if not exist
4- % if path exists, same result as canonical()
5- %
6- % NOTE: some network file systems are not resolvable by Matlab Java
7- % subsystem, but are sometimes still valid--so return
8- % unmodified path if this occurs.
9- %
10- % This also resolves Windows short paths to full long paths.
11- %
1+ function r = resolve(p , expand_tilde )
2+ % resolve path, to cwd if relative
3+ % effectively canonical(absolute(p))
124% %% Inputs
13- % * p: path to resolve
5+ % * p: path to make absolute
6+ % * expand_tilde: expand ~ to username if present
147% %% Outputs
158% * c: resolved path
169% distinct from canonical(), resolve() always returns absolute path
2013 expand_tilde (1 ,1 ) logical = true
2114end
2215
23- if expand_tilde
24- c = stdlib .expanduser(p );
25- else
26- c = p ;
27- end
28-
29- if ispc && startsWith(c , " \\" )
30- % UNC path is not canonicalized
31- return
32- end
33-
34- if ~stdlib .is_absolute(c )
35- % .toAbsolutePath() default is Documents/Matlab, which is probably not wanted.
36- c = stdlib .join(pwd , c );
37- end
38-
39- % https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#getAbsolutePath()
40-
41- c = stdlib .posix(java .io .File(java .io .File(c ).getAbsolutePath()).toPath().normalize());
16+ r = stdlib .canonical(stdlib .absolute(p , expand_tilde ), false );
4217
43- end % function
18+ end
0 commit comments