File tree Expand file tree Collapse file tree 3 files changed +35
-10
lines changed Expand file tree Collapse file tree 3 files changed +35
-10
lines changed Original file line number Diff line number Diff line change 1- function ok = exists(p )
1+ function ok = exists(p , use_java )
22%% exists does path exist
33% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#exists()
44
55arguments
66 p (1 ,1 ) string
7+ use_java (1 ,1 ) logical = false
8+ end
9+
10+ if use_java
11+ % Java takes 2x to 10x as long as intrinsic way worst case
12+ % the intrinsic way above is at least not slower
13+
14+ ok = java .io .File(p ).exists();
15+ else
16+ ok = isfile(p ) || isfolder(p );
717end
818
9- ok = java .io .File(p ).exists();
1019
1120end
Original file line number Diff line number Diff line change 1- function ok = is_readable(file )
1+ function ok = is_readable(file , use_jvm )
22%% is_readable is file readable
33% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isReadable(java.nio.file.Path)
44
55arguments
66 file (1 ,1 ) string
7+ use_jvm (1 ,1 ) logical = false
78end
89
9- % needs absolute()
10- file = stdlib .absolute(file );
10+ if use_jvm
11+ % java is about 10x slower than fileattrib
12+ % needs absolute()
13+ file = stdlib .absolute(file );
1114
12- ok = java .nio .file .Files .isReadable(java .io .File(file ).toPath());
15+ ok = java .nio .file .Files .isReadable(java .io .File(file ).toPath());
16+ else
17+ [status , v ] = fileattrib(file );
18+
19+ ok = status ~= 0 && (v .UserRead || (~isnan(v .GroupRead ) && v .GroupRead ) || (~isnan(v .OtherRead ) && v .OtherRead ));
20+ end
1321
1422end
Original file line number Diff line number Diff line change 1- function ok = is_writable(file )
1+ function ok = is_writable(file , use_jvm )
22%% is_writable
33% is path writable
44% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/Files.html#isWritable(java.nio.file.Path)
55
66arguments
77 file (1 ,1 ) string
8+ use_jvm (1 ,1 ) logical = false
89end
910
10- % needs absolute()
11- file = stdlib .absolute(file );
11+ if use_jvm
12+ % java is about 10x slower than fileattrib
13+ % needs absolute()
14+ file = stdlib .absolute(file );
1215
13- ok = java .nio .file .Files .isWritable(java .io .File(file ).toPath());
16+ ok = java .nio .file .Files .isWritable(java .io .File(file ).toPath());
17+ else
18+ [status , v ] = fileattrib(file );
19+
20+ ok = status ~= 0 && (v .UserWrite || (~isnan(v .GroupWrite ) && v .GroupWrite ) || (~isnan(v .OtherWrite ) && v .OtherWrite ));
21+ end
1422
1523end
You can’t perform that action at this time.
0 commit comments