-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathDirectory.lua
More file actions
78 lines (58 loc) · 1.7 KB
/
Directory.lua
File metadata and controls
78 lines (58 loc) · 1.7 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- \\ Services // --
local HttpService = game:GetService("HttpService")
-- \\ Variables // --
local Module = {}
-- \\ Functions // --
local function CreateBranch(tree: any, branch: any, parentPath: string)
for i, v in branch do
local name = (typeof(v) == "table") and i or v
local path = (parentPath and parentPath.."/" or "")..name
makefolder(path)
tree[name] = path
if typeof(v) == "table" then
CreateBranch(tree, v, path)
end
end
end
-- \\ Main // --
Module.Create = function(tree: any, path: string?)
path = typeof(path) == "string" and path.."/" or ""
local t = {}
for i, v in tree do
local name = (typeof(v) == "table") and i or v
local rootPath = path..name
t.Root = rootPath
makefolder(rootPath)
if typeof(v) == "table" then
CreateBranch(t, v, rootPath)
end
break
end
return t
end
Module.WriteConfig = function(path: string, data: any): boolean
local success = pcall(function()
writefile(path, HttpService:JSONEncode(data))
end)
return success
end
Module.DecodeConfig = function(path: string): (boolean, any)
local success, result = pcall(function()
return HttpService:JSONDecode(readfile(path))
end)
return success, success and result or {}
end
Module.GetFileName = function(path: string, noExtension: boolean): string
local name = path:match("[^/\\]+$") or path
if noExtension then
name = name:gsub("%.[^.]+$", "")
end
return name
end
Module.GetNameFromDirectory = Module.GetFileName
for i, v in Module do
if typeof(v) == "function" then
getgenv()[i] = v
end
end
return Module