![]() |
|
list files in directory |
the_y_man
Member #1,770
December 2001
![]() |
I'm really clueless on this. But how would I, in C or C++ get a list of all files (and maybe store the file names in an array of strings)? I'm not asking you to write code for me, I'm mostly asking for some hints. Thanks.:o |
Chris Katko
Member #1,881
January 2002
![]() |
I believe allegro provides specific functions for this very purpose. [edit] int for_each_file_ex(const char *name, int in_attrib, int out_attrib, int (*callback)(const char *filename, int attrib, void *param), void *param); Under file and compression routines. Sidenote: I wonder why Allegro.CC doesn't have for_each_file_ex() in it's help database for (code)(/code) blocks. -----sig: |
23yrold3yrold
Member #1,134
March 2001
![]() |
Yup. And storing them in an std::vector of std::string's would be just too easy If you're looking for a non-Allegro solution, poach Allegro's source -- |
Billybob
Member #3,136
January 2003
|
gillius
Member #119
April 2000
|
For an interesting lemony twist, I believe Boost provides a library that represents a file system in an STL-like container/tree. Allegro's function is great too but I've used neither so I cannot comment more Gillius |
the_y_man
Member #1,770
December 2001
![]() |
gillius
Member #119
April 2000
|
Please don't take that suggestion (ls or dir) seriously. That's a very bad way of getting a listing of files. Very bad style and approach and technique. Use one of the other ways we've suggested. Gillius |
the_y_man
Member #1,770
December 2001
![]() |
bad style, eh? if so, i will avoid it. Thanks for the heads up. |
kronoman
Member #2,911
November 2002
![]() |
Try this example:
|
Evert
Member #794
November 2000
![]() |
If you want to be independent of Allegro, you can look into the POSIX functions opendir() readdir() and closedir(). They are portable to all UNIX platforms and variants of GCC (including DJGPP and MinGW). They won;t work with MSVC though. |
Billybob
Member #3,136
January 2003
|
Mine is what you call the hacky/dodgy way of doing things heh
|
CGamesPlay
Member #2,559
July 2002
![]() |
for_each_file_ex isn't in the .cc help system because it's a WIP function. for_each_file might not suit your needs (for instance if you only want the files that are directories), but it's the only one in 4.0.1 -- Ryan Patterson - <http://cgamesplay.com/> |
kronoman
Member #2,911
November 2002
![]() |
You can also use:
With this, you can list files, and doing recursive function, for example, list all files in a drive. |
|