Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CreateDir

109 views
Skip to first unread message

Maurice

unread,
Mar 22, 2008, 4:24:52 AM3/22/08
to
Hello:

I would like to use "DirectoryExists" and "CreateDir", I used the bcb5.hlp,
it say to include "Filectrl.hpp", but such a file is not included in the
free version 5.5.
What's the problem? is there any other alternative?

Thanks
Maurice


#include "Filectrl.hpp"

void main()
{
if(!DirectoryExists("c:\\tmp"))
CreateDir("c:\\tmp");
}

Error E2209 e:\my_data\prog\tc\test.cpp 1: Unable to open include file
'Filectr.hpp'
Error E2268 e:\my_data\prog\tc\test.cpp 5: Call to undefined function
'Directory
Exists' in function main()
Error E2268 e:\my_data\prog\tc\test.cpp 6: Call to undefined function
'CreateDir
' in function main()
*** 3 errors in Compile ***


Thomas Maeder [TeamB]

unread,
Mar 22, 2008, 5:40:57 AM3/22/08
to
"Maurice" <mori...@yahoo.fr> writes:

> I would like to use "DirectoryExists" and "CreateDir", I used the bcb5.hlp,
> it say to include "Filectrl.hpp", but such a file is not included in the
> free version 5.5.
> What's the problem?

I have no idea.


> is there any other alternative?

Probably.


> #include "Filectrl.hpp"
>
> void main()

NB: The return type of main() has to be int.

> {
> if(!DirectoryExists("c:\\tmp"))
> CreateDir("c:\\tmp");
> }


E.g.:

#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <dir.h>

int main()
{
if (DIR *dir = opendir("c:\\tmp"))
{
; // directory exists and is accessible
closedir(dir);
}
else if (mkdir("c:\\tmp")==0)
; // directory successfully created
else
; // error handling
}

opendir(), closedir() and mkdir() are POSIX functions. The #includes
you have to use may vary; the ones given above work on C++BuilderX.

[FWIW, there is no <dir.h> on Linux (and it's not needed), and mkdir()
takes another parameter.]

Ed Mulroy [TeamB]

unread,
Mar 22, 2008, 9:34:24 AM3/22/08
to
Version 5.5 is the set of command line tools from C++ Builder 5 but does not
include the VCL, a Delphi-based class library for Windows. The header files
ending in .hpp are VCL items so are not supplied.

A substitute set of functions, DirExists, FileExists and CreateDir are shown
below.
----------------------
#include <windows.h>

const unsigned long NOT_FOUND = 0xFFFFFFFF;

extern "C"
bool WINAPI DirExists(const char *dir_name)
{
unsigned long attribs;

attribs = GetFileAttributes(dir_name);
return (attribs != NOT_FOUND) &&
((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
}

extern "C"
bool WINAPI FileExists(const char *file_name)
{
unsigned long attribs;

attribs = GetFileAttributes(file_name);
return (attribs != NOT_FOUND) &&
((attribs & FILE_ATTRIBUTE_DIRECTORY) == 0);
}

extern "C"
bool WINAPI CreateDir(const char *dir_name)
{
return ! DirExists(dir_name) && CreateDirectory(dir_name, NULL);
}
----------------------

In addition there are other supplied functions which can be used for that
such as those Mr Maeder mentions.

. Ed

> Maurice wrote in message
> news:47e4...@newsgroups.borland.com...

Cesar Rabak

unread,
Mar 23, 2008, 2:11:56 PM3/23/08
to
DMaurice escreveu:

> Hello:
>
> I would like to use "DirectoryExists" and "CreateDir", I used the bcb5.hlp,
> it say to include "Filectrl.hpp", but such a file is not included in the
> free version 5.5.

Did you notice the mention to Sysutils Unit?

0 new messages