Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to manipulate directories ?

This thread is locked; no one can reply to it. rss feed Print
How to manipulate directories ?
LordHolNapul
Member #3,619
June 2003
avatar

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

Tobias Dammers
Member #2,604
August 2002
avatar

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".

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Michael Faerber
Member #4,800
July 2004
avatar

My code for those tasks:

1#ifndef ALLEGRO_WINDOWS
2#include <sys/stat.h>
3#endif
4 
5bool 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 
16bool als::directory_exists(const string& dirname)
17{
18 if (file_exists(dirname.c_str(), FA_DIREC, NULL))
19 return true;
20 return false;
21}

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

LordHolNapul
Member #3,619
June 2003
avatar

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
8-)

Tobias Dammers
Member #2,604
August 2002
avatar

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.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

ReyBrujo
Moderator
January 2001
avatar

Not ANSI, but POSIX:

opendir

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

LordHolNapul
Member #3,619
June 2003
avatar

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 ;)

Go to: