-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdir-tree-to-delete.red
87 lines (69 loc) · 1.64 KB
/
dir-tree-to-delete.red
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
79
80
81
82
83
84
85
86
Red [
Authors: [
"Toomas Vooglaid" {original code}
"Lépine Kong" {evolutions:
- optional directory
- filter by extension (/extension)
- optionally return a block (/return-block)
}
]
Date: "2017-05-07"
Changed: "2018-07-09"
Purpose: "Print a directory tree"
File: "%dir-tree2.red"
]
unless value? '.redlang [
do https://redlang.red
]
.redlang [do-events alias]
do https://redlang.red/toomasv/dir-tree2.red
.treeview: function [
'>folder [any-type! unset!] {optional directory}
/extension >extension {filter by extension}
/return-block {return a block instead of string}
/silent {silent mode}
/build {return the build number for developer}
][
>build: 0.0.0.1.22.1
if build [
unless silent [
print >build
]
return >build
]
switch type?/word get/any '>folder [
unset! [
>folder: %./
]
]
.folder: :>folder
the-tree: dir-tree (.folder)
lines: split the-tree newline
remove lines ; remove first line
if extension [
>extension: remove form >extension ; 0.0.0.1.20 bug here !!! ".red" instead of "red"
filtered-tree: copy ""
forall lines [
line: lines/1
index: index? lines
filename: trim/all line
ext: last (split filename ".")
if (ext = >extension) [
if (filtered-tree <> "") [ ; super bug because forgot () around index? lines
append filtered-tree newline
]
append filtered-tree line
]
]
the-tree: copy filtered-tree
]
unless silent [
print the-tree
]
either return-block [
return lines
][
return the-tree
]
]
.alias .treeview [tree .tree treeview tree-view .tree-view .dir-tree]