This repository was archived by the owner on Aug 9, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMain.hx
More file actions
64 lines (47 loc) · 1.92 KB
/
Main.hx
File metadata and controls
64 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package;
import sys.io.File;
import sys.FileStat;
import sys.FileSystem;
// http://api.haxe.org/sys/io/File.html
// http://old.haxe.org/forum/thread/4271
// http://old.haxe.org/doc/sys/io/filesystem
// http://api.haxe.org/sys/FileSystem.html
// http://api.haxe.org/sys/FileStat.html
class Main {
public static function main () {
//----------------------------------------------------------------------
trace('--- Operations with files ---');
File.saveContent("test.txt", "123 qwe 321"); // make a new text file
trace("File test.txt " + (FileSystem.exists("test.txt") ? "is exists" : "is not exists")); // check file exists
trace("Absolute path of test.txt " + FileSystem.fullPath("test.txt")); // get absolute path of existing relative path
//----------------------------------------------------------------------
trace('--- File attributes ---');
var stat:FileStat = FileSystem.stat("test.txt");
trace("Date of creation: " + stat.ctime);
trace("Date of last reading: " + stat.atime);
trace("Date of last changing: " + stat.mtime);
trace("Size: " + stat.size);
trace("UID: " + stat.uid);
//----------------------------------------------------------------------
trace('--- Copy file ---');
File.copy("test.txt", "test1.txt");
if (FileSystem.exists("test1.txt")) {
trace("File test1.txt: " + File.getContent("test1.txt"));
}
//----------------------------------------------------------------------
trace('--- Rename file ---');
FileSystem.rename("test.txt", "test123.txt");
if (FileSystem.exists("test123.txt")) {
trace("File test123.txt: " + File.getContent("test12.txt"));
}
//----------------------------------------------------------------------
trace('--- Delete file ---');
FileSystem.deleteFile("test1.txt");
if (FileSystem.exists("test1.txt")) {
trace("Error: file wasn't deleted");
}
else {
trace("File was successfully deleted");
}
}
}