07.12.2018, 20:34
Hey
How to load a random file from a folder?
How to load a random file from a folder?
new dir: dHandle, item[40], type, counter, random_file;
dHandle = dir_open("path_here");
while (dir_list(dHandle, item, type))
{
if(type == FM_FILE) counter++;
}
dir_close(dHandle);
random_file = random(counter);
counter = 0;
dHandle = dir_open("path_here");
while (dir_list(dHandle, item, type))
{
if(type == FM_FILE && counter++ == random_file) break;
}
dir_close(dHandle);
printf("random file: \"%s\"", item);
new dir: dHandle, item[40], type, counter, random_file;
dHandle = dir_open("./scriptfiles");
while (dir_list(dHandle, item, type))
{
if(type == FM_FILE && strfind(item, ".map", true, strlen(item) - 4) != -1) counter++;
}
dir_close(dHandle);
random_file = random(counter);
counter = 0;
dHandle = dir_open("./scriptfiles");
while (dir_list(dHandle, item, type))
{
if(type == FM_FILE && strfind(item, ".map", true, strlen(item) - 4) != -1 && counter++ == random_file) break;
}
dir_close(dHandle);
printf("random file: \"%s\"", item);