Skip to content

Commit b95404e

Browse files
committed
is_exe: reusable code and more robust
1 parent 68ab0a0 commit b95404e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

+stdlib/is_exe.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
i = isfile(p);
1313

1414
if ispc()
15-
pe = split(string(getenv("PATHEXT")), pathsep);
16-
i = i & endsWith(stdlib.suffix(p(i)), pe, 'IgnoreCase', true);
15+
i = i & has_windows_executable_suffix(p(i));
1716
end
1817

1918
if ~any(i), return, end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function i = has_windows_executable_suffix(p)
2+
arguments
3+
p string
4+
end
5+
6+
pec = getenv("PATHEXT");
7+
if isempty(pec)
8+
pec = '.COM;.EXE;.BAT;.CMD;';
9+
end
10+
pe = split(string(pec), pathsep);
11+
12+
i = endsWith(stdlib.suffix(p), pe, 'IgnoreCase', true);
13+
14+
end

0 commit comments

Comments
 (0)