You are not logged in.
Pages: 1
I came across this set of scripts. The scr_find_files() looks fantastic: http://gmc.yoyogames.com/index.php?showtopic=256775
I adapted the script so it creates the list automatically instead of using a user-provided one, I made it possible to search for more than one extension at a time and finally I added an argument to search through subdirectories.
// This script searches all files under the specified directory.
// file_find_list(root, extensions, subdir);
// returns a list data structure containing the full path of the files found
// my_list = file_find_list("C:\Windows", ".jpg|.gif|.bmp", true);
var list, subdir_queue, file_name, dir_name, full_path;
list = ds_list_create();
subdir_queue = ds_queue_create();
ds_queue_enqueue(subdir_queue, argument0);
argument1 = "|" + argument1 + "|";
while (!ds_queue_empty(subdir_queue))
{
dir_name = ds_queue_dequeue(subdir_queue);
file_name = file_find_first(dir_name + '\*', fa_directory);
while (file_name != '')
{
full_path = dir_name + '\' + file_name;
if (file_attributes(full_path, fa_directory) && argument2)
{
if (file_name != '.' && file_name != '..')
{
ds_queue_enqueue(subdir_queue, full_path);
}
}
else
{
if (string_pos("|" + string_lower(filename_ext(file_name)) + "|", argument1) > 0)
{
ds_list_add(list, full_path);
}
}
file_name = file_find_next();
}
file_find_close();
}
ds_queue_destroy(subdir_queue);
return (list);
A quick test (don't forget to destroy the list) :
list = file_find_list(get_directory(''), get_string("File extension :", ".jpg|.gif|.bmp"), true);
var i;
for (i=0; i<ds_list_size(list); i+=1)
{
draw_text(50, 50 + 30*i, ds_list_find_value(list, i));
}
The script would probably be faster if instead of delimiting the extensions the script asked for an array (for loop comparison) or a list (ds_list_find_index > -1). Have your say!
Cheers,
Quimp
Offline
Thanks for pointing out this script, Quimp. I'd been wanting to get something like this for the site, I just never got around to writing it. Since at first glance this looks pretty close to torigara's script I'll need to get his permission before I can accept this.
Abusing forum power since 1986.
Offline
Nice work Quimp. I'll be using this one.
Offline
just wondering, why do you use this check:
if (file_name != '.' && file_name != '..')
? - I believe directories can't have a name of simply dots, so it can't happen that that if statment returns false. And if it is to prevent faultry filenames, (which windows prevents), you should also check for: "\/?:*<>|" - and for any number of dots, like:
if (string_count(file_name,".")=string_length(filename) /*&& string_pos("\") = 0 && string_pos("/") = 0 && string_pos("?") = 0 && string_pos(":") = 0 && string_pos("*") = 0 && string_pos("<") = 0 && string_pos(">") = 0 && string_pos("|") = 0*/ )
(commented code is if you want to test it completely)
However there might be a better reason to check for 1 or 2 dots?
Offline
The big chuck was indeed written by torigara. I was heading towards PMing him/her for a submission here, when I finally decided to make some modifications. But they're minor, so I'd rather see torigara in the credits than my name.
Offline
However there might be a better reason to check for 1 or 2 dots?
Those are special meta-directories. One dot means the current directory, two dots mean the parent directory. I haven't tested this out yet to see if the check is necessary, but it's hardly unusual for this kind of procedure; in many languages/APIs not checking for them can lead to an infinite loop.
The big chuck was indeed written by torigara. I was heading towards PMing him/her for a submission here, when I finally decided to make some modifications. But they're minor, so I'd rather see torigara in the credits than my name.
Both of you would get credit, and maybe paul23 as well. Now somebody cook up an indefinite gender pronoun for English, I really despise he/she/him/her.
Abusing forum power since 1986.
Offline
I always use "they" for that.
Offline
Pages: 1