![]() |
|
A5: Allegro File System error |
TeaRDoWN
Member #8,518
April 2007
![]() |
EDIT: Solved! Forgot to run al_open_directory(ALLEGRO_FS_ENTRY); I've made two functions that I am going to use to parse directories and get all files in them. The idea is that I only send the directory path to td_set_directory_to_parse() and then call td_next_file_in_directory() until it returns NULL. I've used these functions before without problem but then I logged all files and subdirectories to "content files" in each directory (old approach from back when I used A4 which I've converted to A5), but now I want to do it runtime instead of generating these content files. Problem is that it crashes when I run al_read_directory(ParseDirectory); in the td_next_file_in_directory() function and I don't know why. ParseDirectory has been set to a File System entity and if I wouldn't it would be NULL and return NULL. Anyone able to see what I've forgotten? I've been looking at the code for a few hours now and can't find it. 1ALLEGRO_FS_ENTRY *ParseDirectory = NULL;
2
3void td_set_directory_to_parse(char *path)
4{
5 if (ParseDirectory != NULL)
6 al_destroy_fs_entry(ParseDirectory);
7
8 ParseDirectory = al_create_fs_entry(path);
9}
10
11
12char *td_next_file_in_directory()
13{
14 if (ParseDirectory == NULL)
15 return NULL;
16
17 ALLEGRO_FS_ENTRY *file = al_read_directory(ParseDirectory); // <-- Crash!
18
19 if (al_get_fs_entry_mode(file) & ALLEGRO_FILEMODE_ISFILE)
20 {
21 char *fileName = td_malloc(64);
22 sprintf(fileName, "%s", al_get_fs_entry_name(file));
23 return fileName;
24 }
25 else
26 {
27 al_destroy_fs_entry(ParseDirectory);
28 return NULL;
29 }
30}
|
|