Hi everyone,
I would like to know how to create, test if exists, and delete a Directory.
Wich is the include .h to use ? Can you post to me some examples ?
Thank you.
ciao:P
You can do this with allegro routines, or use the libc equivalents. Remember that a directory is basically a file with the directory flag set (only you cannot read from it or write to it).
For allegro routines, this means that you need to add FA_DIREC in the appropriate places. RTFM for more info; look into "File and compression routines".
My code for those tasks:
| 1 | #ifndef ALLEGRO_WINDOWS |
| 2 | #include <sys/stat.h> |
| 3 | #endif |
| 4 | |
| 5 | bool als::create_directory(const string& directory) |
| 6 | { |
| 7 | #ifdef ALLEGRO_WINDOWS |
| 8 | return CreateDirectory(directory.c_str(), NULL); |
| 9 | #else |
| 10 | return mkdir(directory.c_str(), S_IRWXU | |
| 11 | S_IRGRP | S_IXGRP | |
| 12 | S_IROTH | S_IXOTH); |
| 13 | #endif |
| 14 | } |
| 15 | |
| 16 | bool als::directory_exists(const string& dirname) |
| 17 | { |
| 18 | if (file_exists(dirname.c_str(), FA_DIREC, NULL)) |
| 19 | return true; |
| 20 | return false; |
| 21 | } |
Thank you, in this case I haven't Allegro opened and I want to manage directories..
So you say that the library to manage this is "#include <sys/stat.h>" .
I hope this is a standard library and I'll try later.... 
ciao
It's not a lib, but a header. But anyway, libc (which either (windows) links statically or (linux) can be assumed to be on the target system) should have appropriate calls too. Otherwise you might want to use the respective platform's native file system api.
Not ANSI, but POSIX:
I've found that you don't understood my problem... but you put me to the right way...
What I was looking for was , finally, the #include <direct.h> that can be manipulated to manage directories....
I've found only this old document that specify a maximum dir lenght of 64 bytes included \0, but it's not true. I've tried the code with 200 byte directory and it works fine...
here the link if you are interested :
http://www.digitalmars.com/rtl/direct.html#_chdir
see you next time! We will speak of Open Layer