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 ***
> 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.]
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...
Did you notice the mention to Sysutils Unit?