Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » problems with al_findfirst

Credits go to Evert and Synapse Jumps for helping out!
This thread is locked; no one can reply to it. rss feed Print
problems with al_findfirst
Mark Oates
Member #1,146
March 2001
avatar

I'm trying to do a simple search and list files in a directory. This is my code and for some reason it doesn't find any files:

what am I doing wrong?

1void search_for_files(string search_criteria="*.htm")
2{
3 al_ffblk info;
4 
5 string gimp_string = "";
6 
7 if (al_findfirst(search_criteria.c_str(), &info, 0) == 0)
8 {
9 do
10 {
11 gimp_string = ToString(info.name);
12 allegro_message(gimp_string.c_str());
13 } while (al_findnext(&info) == 0);
14 }
15 else allegro_message("no files found");
16 
17 al_findclose(&info);
18}

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Synapse Jumps
Member #3,073
December 2002

Try specifying an absolute path, IE: "C:\*.htm", also, keep in mind these don't search recursively, so if you have folders IN whichever folder you're running this, it won't work properly.

Evert
Member #794
November 2000
avatar

Quote:

what am I doing wrong?

What almost everyone does wrong ;) :

Quote:

al_findfirst(search_criteria.c_str(), &info, 0)

By passing 0, you are exclusing all files that have any attributes set (keep reading http://alleg.sourceforge.net/onlinedocs/en/alleg030.html until this makes sense). Pass FA_ALL instead (this is not documented in the 4.2 documentation due to an oversight, it is in SVN). The SVN documentation also has a less confusing description of what the flags do than the one in the current documentation.

Mark Oates
Member #1,146
March 2001
avatar

Ah, twas the example in the documentation. FA_ALL is not diclared in the version I'm using - 4.2.0(beta3). so I did this:

#define FA_ALL FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_LABEL | FA_DIREC | FA_ARCH

(any I missed?)

on a different note:
I've been using the online manual from allegro.cc, the last paragraph is doubled on some of these al_find* entries.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Go to: