Функции для работы с файлами

This commit is contained in:
Victor 2016-02-28 10:52:18 +02:00
parent ef701c979f
commit c67060a7f3

View File

@ -31,6 +31,12 @@ public final class files implements Module {
Functions.set("fopen", new fopen()); Functions.set("fopen", new fopen());
Functions.set("listFiles", new listFiles()); 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("readBoolean", new readBoolean());
Functions.set("readByte", new readByte()); Functions.set("readByte", new readByte());
Functions.set("readBytes", new readBytes()); 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 { private static class readBoolean extends FileFunction {
@Override @Override
protected Value execute(FileInfo fileInfo, Value[] args) throws IOException { protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {