-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.src
51 lines (48 loc) · 1.43 KB
/
tree.src
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
//command: tree
if not params or params.len == 0 then
folderPath = current_path
else if params.len > 1 or params[0] == "-h" or params[0] == "--help" then
exit("Usage: tree [opt: path]")
else
folderPath = params[0]
end if
folder = get_shell.host_computer.File(folderPath)
if folder == null then
print("tree: No such file or directory")
else if not folder.has_permission("r") then
print("tree: permission denied")
else
printElement = function(currentElement, indent, last)
if currentElement.is_folder then
print(indent + "<color=#2390B2FF>" + currentElement.name + "</color>")
else if currentElement.is_binary then
print(indent + "<color=#D1304FFF>" + currentElement.name + "</color>")
else
print(indent + currentElement.name)
end if
if currentElement.is_folder then
if indent.len == 0 then
indent = "|--"
else if last then
indent = indent[0:-3] + " " + "|--"
else
indent = indent[0:-3] + "| " + "|--"
end if
subFiles = []
for f in currentElement.get_folders
subFiles.push({"name":f.name, "file":f})
end for
for f in currentElement.get_files
subFiles.push({"name":f.name, "file":f})
end for
subFiles.sort("name")
index = 0
for sub in subFiles
last = (index == subFiles.len-1)
printElement(sub["file"], indent, last)
index = index + 1
end for
end if
end function
printElement(folder, "", true)
end if