We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3d5cca6 commit 16ed8f5Copy full SHA for 16ed8f5
+stdlib/+fileio/expanduser.m
@@ -6,11 +6,7 @@
6
7
expanded = p;
8
9
-if ispc
10
- home = getenv('USERPROFILE');
11
-else
12
- home = getenv('HOME');
13
-end
+home = stdlib.fileio.homedir();
14
15
if ~isempty(home)
16
i = startsWith(expanded, "~");
+stdlib/+fileio/homedir.m
@@ -0,0 +1,27 @@
1
+function home = homedir()
2
+
3
+persistent h;
4
5
+if ~isempty(h)
+ home = h;
+ return
+end
+try
+ home = string(java.lang.System.getProperty("user.home"));
+catch excp
+ % if Java not available use env vars, else error
+ if excp.identifier ~= "MATLAB:undefinedVarOrClass"
+ error("stdlib:fileio:homedir", excp.message)
+ end
17
18
+ if ispc
19
+ home = getenv('USERPROFILE');
20
+ else
21
+ home = getenv('HOME');
22
23
24
25
+h = home;
26
27
0 commit comments