2022-12-16 09:18:09 +01:00
|
|
|
function path_search(paths, recur = false, _filter = "") {
|
|
|
|
var _paths = [];
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(paths); i < n; i++ ) {
|
2022-12-16 09:18:09 +01:00
|
|
|
array_append(_paths, paths_to_array(paths[i], recur, _filter));
|
|
|
|
}
|
|
|
|
return _paths;
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
function paths_to_array(paths, recur = false, _filter = "") {
|
|
|
|
var _paths = [];
|
|
|
|
var in = 0;
|
|
|
|
|
|
|
|
if(directory_exists(paths)) {
|
|
|
|
var st = ds_stack_create();
|
|
|
|
ds_stack_push(st, paths);
|
|
|
|
var regx = new regex_tree(_filter);
|
|
|
|
|
|
|
|
while(!ds_stack_empty(st)) {
|
|
|
|
var curr_path = ds_stack_pop(st);
|
|
|
|
|
|
|
|
var file = file_find_first(curr_path + "/*", fa_directory);
|
|
|
|
while(file != "") {
|
|
|
|
var file_full = curr_path + "/" + file;
|
|
|
|
if(directory_exists(file_full) && recur) {
|
|
|
|
ds_stack_push(st, file_full);
|
2023-03-24 05:55:34 +01:00
|
|
|
} else if(path_is_image(file_full) && regx.isMatch(file_full)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
array_push(_paths, file_full);
|
|
|
|
}
|
|
|
|
|
|
|
|
file = file_find_next();
|
|
|
|
}
|
|
|
|
file_find_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_stack_destroy(st);
|
2023-12-08 03:50:09 +01:00
|
|
|
} else if(file_exists_empty(paths))
|
2022-12-16 09:18:09 +01:00
|
|
|
array_push(_paths, paths);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
return _paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
function path_is_image(path) {
|
2023-12-08 03:50:09 +01:00
|
|
|
if(!file_exists_empty(path)) return false;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var ext = filename_ext(path);
|
|
|
|
switch(ext) {
|
|
|
|
case ".png":
|
|
|
|
case ".jpg":
|
|
|
|
case ".jpeg":
|
|
|
|
case ".gif":
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|