Skip to content

Commit c67060a

Browse files
committed
Функции для работы с файлами
1 parent ef701c9 commit c67060a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/com/annimon/ownlang/lib/modules/files.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public void init() {
3131

3232
Functions.set("fopen", new fopen());
3333
Functions.set("listFiles", new listFiles());
34+
Functions.set("delete", new delete());
35+
Functions.set("exists", new exists());
36+
Functions.set("isDirectory", new isDirectory());
37+
Functions.set("isFile", new isFile());
38+
Functions.set("mkdir", new mkdir());
39+
Functions.set("fileSize", new fileSize());
3440
Functions.set("readBoolean", new readBoolean());
3541
Functions.set("readByte", new readByte());
3642
Functions.set("readBytes", new readBytes());
@@ -128,6 +134,48 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
128134
}
129135
}
130136

137+
private static class delete extends FileFunction {
138+
@Override
139+
protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
140+
return NumberValue.fromBoolean(fileInfo.file.delete());
141+
}
142+
}
143+
144+
private static class exists extends FileFunction {
145+
@Override
146+
protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
147+
return NumberValue.fromBoolean(fileInfo.file.exists());
148+
}
149+
}
150+
151+
private static class isDirectory extends FileFunction {
152+
@Override
153+
protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
154+
return NumberValue.fromBoolean(fileInfo.file.isDirectory());
155+
}
156+
}
157+
158+
private static class isFile extends FileFunction {
159+
@Override
160+
protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
161+
return NumberValue.fromBoolean(fileInfo.file.isFile());
162+
}
163+
}
164+
165+
private static class mkdir extends FileFunction {
166+
@Override
167+
protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
168+
return NumberValue.fromBoolean(fileInfo.file.mkdir());
169+
}
170+
}
171+
172+
private static class fileSize extends FileFunction {
173+
@Override
174+
protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
175+
return new NumberValue(fileInfo.file.length());
176+
}
177+
}
178+
131179
private static class readBoolean extends FileFunction {
132180
@Override
133181
protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {

0 commit comments

Comments
 (0)