From c67060a7f3ffba476d7af22c8cd324aa1be60ae3 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 28 Feb 2016 10:52:18 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20?= =?UTF-8?q?=D1=81=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annimon/ownlang/lib/modules/files.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/com/annimon/ownlang/lib/modules/files.java b/src/com/annimon/ownlang/lib/modules/files.java index 979c399..2fdffc4 100644 --- a/src/com/annimon/ownlang/lib/modules/files.java +++ b/src/com/annimon/ownlang/lib/modules/files.java @@ -31,6 +31,12 @@ public final class files implements Module { Functions.set("fopen", new fopen()); Functions.set("listFiles", new listFiles()); + Functions.set("delete", new delete()); + Functions.set("exists", new exists()); + Functions.set("isDirectory", new isDirectory()); + Functions.set("isFile", new isFile()); + Functions.set("mkdir", new mkdir()); + Functions.set("fileSize", new fileSize()); Functions.set("readBoolean", new readBoolean()); Functions.set("readByte", new readByte()); Functions.set("readBytes", new readBytes()); @@ -128,6 +134,48 @@ public final class files implements Module { } } + private static class delete extends FileFunction { + @Override + protected Value execute(FileInfo fileInfo, Value[] args) throws IOException { + return NumberValue.fromBoolean(fileInfo.file.delete()); + } + } + + private static class exists extends FileFunction { + @Override + protected Value execute(FileInfo fileInfo, Value[] args) throws IOException { + return NumberValue.fromBoolean(fileInfo.file.exists()); + } + } + + private static class isDirectory extends FileFunction { + @Override + protected Value execute(FileInfo fileInfo, Value[] args) throws IOException { + return NumberValue.fromBoolean(fileInfo.file.isDirectory()); + } + } + + private static class isFile extends FileFunction { + @Override + protected Value execute(FileInfo fileInfo, Value[] args) throws IOException { + return NumberValue.fromBoolean(fileInfo.file.isFile()); + } + } + + private static class mkdir extends FileFunction { + @Override + protected Value execute(FileInfo fileInfo, Value[] args) throws IOException { + return NumberValue.fromBoolean(fileInfo.file.mkdir()); + } + } + + private static class fileSize extends FileFunction { + @Override + protected Value execute(FileInfo fileInfo, Value[] args) throws IOException { + return new NumberValue(fileInfo.file.length()); + } + } + private static class readBoolean extends FileFunction { @Override protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {