-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFileSystem.gd
62 lines (47 loc) · 1.21 KB
/
FileSystem.gd
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
extends Reference
class_name FileSystem
"""
Used to write the component text to a temporary file
so that the result can be displayed.
"""
static func save_component(path, component_text):
var file = File.new()
file.open(path, File.WRITE)
file.store_string(component_text)
file.close()
"""
Used to clear a file after a successful execution.
"""
static func clear_file(path):
save_component(path, "")
"""
Loads the text of a file into a string to be manipulated by the GUI.
"""
static func load_file_text(path):
var f = File.new()
var err = f.open(path, File.READ)
if err != OK:
printerr("Could not open file, error code ", err)
return ""
var text = f.get_as_text()
f.close()
return text
"""
Determines the parent directory given a path string.
"""
static func find_parent_dir(path):
var path_parts = path.split('/')
# Remove the directory/file from the end of the path
path_parts.remove(path_parts.size() - 1)
# Reassemble the path without the end
var par_path = ""
for part in path_parts:
par_path += "/"
par_path += part
return par_path
"""
Extracts the destination file/directory from a given path.
"""
static func find_end_of_path(path):
var path_parts = path.split('/')
return path_parts[-1]