Discussion:
CreateDir
(too old to reply)
Maurice
2008-03-22 08:24:52 UTC
Permalink
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]
2008-03-22 09:40:57 UTC
Permalink
Post by Maurice
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.
Post by Maurice
is there any other alternative?
Probably.
Post by Maurice
#include "Filectrl.hpp"
void main()
NB: The return type of main() has to be int.
Post by Maurice
{
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]
2008-03-22 13:34:24 UTC
Permalink
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
Post by Maurice
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 ***
Cesar Rabak
2008-03-23 18:11:56 UTC
Permalink
Post by Maurice
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?

Loading...