-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_filelist_array.tpa
45 lines (41 loc) · 1.5 KB
/
generate_filelist_array.tpa
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
// Action function for generating associative array listing all files inside specified path and all its subdirectories (file path => extension)
//Example usage:
/*LAF GENERATE_FILELIST_ARRAY STR_VAR path = EVAL ~%MOD_FOLDER%~ RET_ARRAY filelist_array = filelist END
ACTION_PHP_EACH filelist_array AS file => ext BEGIN
PRINT ~%file% => %ext%~
END*/
DEFINE_ACTION_FUNCTION GENERATE_FILELIST_ARRAY
STR_VAR
path = EVAL "%MOD_FOLDER%" //path to top directory from which files and directories lookup starts (defaults to %MOD_FOLDER%)
RET_ARRAY
filelist //returned associative array containing all filenames and additional file data
BEGIN
OUTER_PATCH_SAVE path ~%path%~ BEGIN
REPLACE_TEXTUALLY ~\\~ ~/~
REPLACE_TEXTUALLY ~^\./~ ~~
REPLACE_TEXTUALLY ~/$~ ~~
END
LAF generate_filelist_internal STR_VAR path = EVAL ~%path%~ RET_ARRAY filelist END
END
//used internally by GENERATE_FILELIST_ARRAY function
DEFINE_ACTION_FUNCTION generate_filelist_internal
STR_VAR
path = ""
RET_ARRAY
filelist
BEGIN
ACTION_CLEAR_ARRAY loopfiles_array
GET_FILE_ARRAY loopfiles_array ~%path%~ ~~
ACTION_PHP_EACH loopfiles_array AS index => file BEGIN
OUTER_PATCH_SAVE ext ~%file%~ BEGIN
REPLACE_TEXTUALLY ~^.+\.\([^\.]+\)$~ ~\1~
END
ACTION_TO_LOWER ext
OUTER_SPRINT $filelist("%file%") "%ext%"
END
ACTION_CLEAR_ARRAY loopdirs_array
GET_DIRECTORY_ARRAY loopdirs_array ~%path%~ ~~
ACTION_PHP_EACH loopdirs_array AS index => dir BEGIN
LAF generate_filelist_internal STR_VAR path = EVAL ~%dir%~ RET_ARRAY filelist END
END
END