|
How to get all files in a directory with A5 |
Don Freeman
Member #5,110
October 2004
|
I know the older version of Allegro had the for_each_file thing, what should I use with A5 to get all the files in a directory? -- |
Matthew Leverton
Supreme Loser
January 1999
|
Don Freeman
Member #5,110
October 2004
|
I figured as much, but what kind of iteration device do I use?! I see nothing in the manual about such devices. -- |
SiegeLord
Member #7,827
October 2006
|
This will print the name of everything in the passed directory. 1#include <stdio.h>
2#include <allegro5/allegro.h>
3
4int main(int argc, char *argv[])
5{
6 if(argc > 1)
7 {
8 al_init();
9
10 ALLEGRO_FS_ENTRY* dir = al_create_fs_entry(argv[1]);
11 if(al_open_directory(dir))
12 {
13 ALLEGRO_FS_ENTRY* file;
14 while(file = al_read_directory(dir))
15 {
16 printf("%s\n", al_get_fs_entry_name(file));
17 al_destroy_fs_entry(file);
18 }
19 }
20 al_destroy_fs_entry(dir);
21 return 0;
22 }
23}
"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Don Freeman
Member #5,110
October 2004
|
Thanks guys....just got it right before you posted. I think the function names are a little confusing in this regard... Maybe should post an example of this in the wiki. I start feeling a little better and get some free time, I might do it. Thanks again. -- |
SiegeLord
Member #7,827
October 2006
|
Hmm. I wonder how you tell if an FS_ENTRY is a file or a directory. Also, it'd be nice to be able to get the ALLEGRO_PATH from an FS_ENTRY without using the potentially unsafe al_get_fs_entry_name. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Elias
Member #358
May 2000
|
SiegeLord said: Hmm. I wonder how you tell if an FS_ENTRY is a file or a directory. al_get_fs_entry_mode(entry) & ALLEGRO_FILEMODE_ISDIR Does nobody ever look at the examples? There's an ex_dir which re-imlpements the ls command with the A5 API... Quote: Also, it'd be nice to be able to get the ALLEGRO_PATH from an FS_ENTRY without using the potentially unsafe al_get_fs_entry_name. Even better would be if you could get an ALLEGRO_FILE since if filenames are not encoded as utf8 both a string as well as ALLEGRO_PATH would break it. -- |
SiegeLord
Member #7,827
October 2006
|
Elias said: Does nobody ever look at the examples? I blame the binary distribution . "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Thomas Fjellstrom
Member #476
June 2000
|
Elias said: Even better would be if you could get an ALLEGRO_FILE since if filenames are not encoded as utf8 both a string as well as ALLEGRO_PATH would break it. That all used to just work with the original API I think the old way was thought to be too confusing. Ah well. -- |
Elias
Member #358
May 2000
|
SiegeLord said: I blame the binary distribution . Maybe we should package binaries of the examples as well? It would increase the size quite a bit though (especially with static linking). But it would also make it easier to test out A5, just downloading the library with nothing to run is a bit boring -- |
Thomas Fjellstrom
Member #476
June 2000
|
Maybe provide a separate "example/demo" binary that contains the example sources and binaries. -- |
Arthur Kalliokoski
Second in Command
February 2005
|
They'd need the example source files to learn from, and if their binary distribution is OK, a simple makefile with compiler options should suffice. They all watch too much MSNBC... they get ideas. |
AMCerasoli
Member #11,955
May 2010
|
that would be great, I always thought why there weren't examples at the binaries if it's what almost everybody uses (at least in windows)...
|
Evert
Member #794
November 2000
|
Elias said: Maybe we should package binaries of the examples as well? It would increase the size quite a bit though (especially with static linking). I don't think there's much point in a binary distribution of the examples, to be honest. Now, a test program I could see the use of (I know most of the examples are really test programs in disguise). However, it would make sense (to me) to include the example sources in the binary package (for Windows anyway, for Linux it should probably be a separate package). |
Elias
Member #358
May 2000
|
Don't know, when I tried for example Ogre3D I really liked how I could try their examples before I had to commit and actually install and compile stuff. -- |
LennyLen
Member #5,313
December 2004
|
The examples are provided in binary form here on A.cc.
|
Matthew Leverton
Supreme Loser
January 1999
|
There's also usually working examples linked to each online manual page via forum discussions. Sitting across the Internet, you cannot force someone to click and read. |
|