File tree Expand file tree Collapse file tree 3 files changed +32
-18
lines changed Expand file tree Collapse file tree 3 files changed +32
-18
lines changed Original file line number Diff line number Diff line change @@ -78,14 +78,20 @@ function test_makedir(tc)
78
78
79
79
function test_which(tc )
80
80
import stdlib .fileio .which
81
+ import stdlib.fileio.is_exe
81
82
82
83
n = " matlab" ;
83
- % assumes Matlab in environment variable PATH
84
- tc .assumeNotEmpty (which(n ))
85
-
84
+ %% which: Matlab in environment variable PATH
85
+ tc .verifyNotEmpty (which(n ))
86
+ %% is_exe test
86
87
p = fullfile(matlabroot , " bin" , n );
87
-
88
- % full absolute path
88
+ if ispc
89
+ fp = p + " .exe" ;
90
+ else
91
+ fp = p ;
92
+ end
93
+ tc .verifyTrue(is_exe(fp ))
94
+ %% which: test absolute path
89
95
exe = which(p );
90
96
91
97
if ispc
Original file line number Diff line number Diff line change
1
+ function ok = is_exe(file )
2
+ %% ok = is_exe(file)
3
+ % is a file executable?
4
+
5
+ arguments
6
+ file (1 ,1 ) string
7
+ end
8
+
9
+ if ~isfile(file )
10
+ ok = false ;
11
+ return
12
+ end
13
+
14
+ [ok1 , stat ] = fileattrib(file );
15
+ ok = ok1 == 1 && (stat .UserExecute == 1 || stat .GroupExecute == 1 );
16
+
17
+ end
Original file line number Diff line number Diff line change 8
8
subdir (1 ,: ) string {mustBeNonempty } = " "
9
9
end
10
10
11
+ import stdlib.fileio.is_exe
12
+
11
13
exe = string .empty ;
12
14
13
15
if ispc
20
22
if any(strlength(fileparts(name )) > 0 )
21
23
% has directory part
22
24
for n = name
23
- if check_exe (n )
25
+ if is_exe (n )
24
26
exe = n ;
25
27
break
26
28
end
40
42
for s = subdir
41
43
for n = name
42
44
e = fullfile(p , s , n );
43
- if check_exe (e )
45
+ if is_exe (e )
44
46
exe = e ;
45
47
return
46
48
end
50
52
end
51
53
52
54
end
53
-
54
-
55
- function ok = check_exe(exe )
56
- arguments
57
- exe (1 ,1 ) string
58
- end
59
-
60
- [ok1 , stat ] = fileattrib(exe );
61
- ok = ok1 == 1 && (stat .UserExecute == 1 || stat .GroupExecute == 1 );
62
-
63
- end
You can’t perform that action at this time.
0 commit comments