Pixel-Composer/scripts/path_reader/path_reader.gml
2022-12-16 15:18:09 +07:00

56 lines
1.2 KiB
Plaintext

function path_search(paths, recur = false, _filter = "") {
var _paths = [];
for( var i = 0; i < array_length(paths); i++ ) {
array_append(_paths, paths_to_array(paths[i], recur, _filter));
}
return _paths;
}
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);
} else if(path_is_image(file_full) && regx.eval(file_full)) {
array_push(_paths, file_full);
}
file = file_find_next();
}
file_find_close();
}
regx.free();
delete regx;
ds_stack_destroy(st);
} else if(file_exists(paths))
array_push(_paths, paths);
return _paths;
}
function path_is_image(path) {
if(!file_exists(path)) return false;
var ext = filename_ext(path);
switch(ext) {
case ".png":
case ".jpg":
case ".jpeg":
case ".gif":
return true;
}
return false;
}