mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-26 15:06:22 +01:00
54 lines
No EOL
1.2 KiB
Text
54 lines
No EOL
1.2 KiB
Text
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.isMatch(file_full)) {
|
|
array_push(_paths, file_full);
|
|
}
|
|
|
|
file = file_find_next();
|
|
}
|
|
file_find_close();
|
|
}
|
|
|
|
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;
|
|
} |