Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] al_read_directory() odd behavior

This thread is locked; no one can reply to it. rss feed Print
[A5] al_read_directory() odd behavior
aureneas
Member #16,559
September 2016

So what I'm doing is this. I create an FS_ENTRY with a path to my lib folder, then open the directory and try to read the files inside. I've confirmed that the FS_ENTRY exists and is a valid path, and when I try to read the files in the directory, it is able to create a not-null FS_ENTRY for all objects in the directory. The problem is that the path for each of these FS_ENTRY objects is "C:\...\lib\" and al_fs_entry_exists() returns false for all of them.

#SelectExpand
1// created a FS_ENTRY* dir with a path to lib folder 2 3if (al_get_fs_entry_mode(dir) & ALLEGRO_FILEMODE_ISDIR) { 4 5 if (al_open_directory(dir)) { 6 7 ALLEGRO_FS_ENTRY* file; 8 while (file = al_read_directory(dir)) { 9 10 if (al_fs_entry_exists(file)) { 11 12 // execute code 13 } 14 15 al_destroy_fs_entry(file); 16 } 17 18 al_close_directory(dir); 19 } 20}

I'm compiling this program on Windows 10. I'm not sure if this is an issue with my code or with Allegro -- has anyone else had an issue similar to this, or can at least offer advice?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Hey Aureneas,

How are you creating your original ALLEGRO_FS_ENTRY? Are you using al_create_fs_entry with a relative or absolute path? It seems to work with relative paths on my system. What is the full directory path to your lib folder? Perhaps there is a limitation on the number of characters in the path.

FSentry.cpp
list.exe (statically linked directory listing program)
(Use with a directory as argument or with no argument the current directory is used).

I had this old test program lying around and I ran it on my Windows 10 machine after rebuilding it with MinGW 5.3.0-2 and Allegro 5.2.1.1 and it seems to list directory contents just fine. Give it a try and see if it works for you. If so, maybe there is some code difference? Are you compiling with MinGW or MSVC? Or Clang or Borland maybe?

aureneas
Member #16,559
September 2016

Hmm... list.exe seems to work fine, but when I compiled FSentry.cpp with a full directory path of "C:\Programs\test" it produced the same result as before. So I suppose it's not an issue with code, but an issue with the way my machine is compiling it?

My compiler is MinGW 5.3.0, with Allegro 5.0.10 (my version came bundled with MinGW 4.7.0), and I'm statically linking to the Allegro library in Code::Blocks. Do you upgrading to 5.2.1.1 would fix the problem, or do you think the issue is something else?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

It's probably a library version problem. Also, you shouldn't mix binaries of Allegro for MinGW 4.7 with MinGW 5.3. The version of MinGW used needs to match.

Yes, you should upgrade. 5.0.10 is pretty old. I have binaries for MinGW 5.3.0-2 and Allegro 5.2.1.1 here :

https://www.allegro.cc/forums/thread/616446

Go to: