Skip to content

Commit 6197925

Browse files
committed
add is_writable, is_readable
add exists()
1 parent 60268dd commit 6197925

File tree

7 files changed

+77
-1
lines changed

7 files changed

+77
-1
lines changed

+stdlib/+fileio/exists.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function ok = exists(p)
2+
%% exists does path exist
3+
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#exists()
4+
5+
arguments
6+
p (1,1) string
7+
end
8+
9+
10+
ok = java.io.File(p).exists();
11+
12+
end

+stdlib/+fileio/is_readable.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function ok = is_readable(file)
2+
%% is_readable is file readable
3+
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isReadable(java.nio.file.Path)
4+
5+
arguments
6+
file string {mustBeScalarOrEmpty}
7+
end
8+
9+
if isempty(file)
10+
ok = logical.empty;
11+
return
12+
end
13+
14+
15+
ok = java.nio.file.Files.isReadable(java.io.File(stdlib.fileio.absolute_path(file)).toPath());
16+
17+
end

+stdlib/+fileio/is_writable.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function ok = is_writable(file)
2+
%% is_writable is file writable
3+
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isWritable(java.nio.file.Path)
4+
5+
arguments
6+
file string {mustBeScalarOrEmpty}
7+
end
8+
9+
if isempty(file)
10+
ok = logical.empty;
11+
return
12+
end
13+
14+
15+
ok = java.nio.file.Files.isWritable(java.io.File(stdlib.fileio.absolute_path(file)).toPath());
16+
17+
end

+stdlib/exists.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function ok = exists(p)
2+
%% exists does path exist
3+
4+
arguments
5+
p (1,1) string
6+
end
7+
8+
ok = stdlib.fileio.exists(p);
9+
10+
end

+stdlib/is_readable.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function ok = is_readable(p)
2+
%% is_readable() returns true if the file at path p is readable
3+
4+
arguments
5+
p (1,1) string
6+
end
7+
8+
ok = stdlib.fileio.is_readable(p);
9+
10+
end

+stdlib/is_writable.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function ok = is_writable(p)
2+
%% is_writable() returns true if the file at path p is writable
3+
4+
arguments
5+
p (1,1) string
6+
end
7+
8+
ok = stdlib.fileio.is_writable(p);
9+
10+
end

test/TestFileImpure.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function test_is_readable(tc)
3535
function test_is_writable(tc)
3636

3737
tc.verifyTrue(stdlib.is_writable(pwd))
38-
tc.verifyFalse(stdlib.is_writable(matlabroot))
38+
% tc.verifyFalse(stdlib.is_writable(matlabroot)) % on CI this can be writable!
3939
tc.verifyFalse(stdlib.is_writable("not-exists"))
4040

4141
end

0 commit comments

Comments
 (0)