|
| Re: CreateDir |
 |
Sat, 22 Mar 2008 09:34:24 -040 |
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:47e4c2f8@newsgroups.borland.com...
>
> 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 ***
|
| Post Reply
|
| CreateDir |
 |
Sat, 22 Mar 2008 10:24:52 +020 |
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 ***
|
| Post Reply
|
| Re: CreateDir |
 |
Sat, 22 Mar 2008 10:40:57 +010 |
"Maurice" <morisaab@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()
|
| Post Reply
|
| Re: CreateDir |
 |
Sun, 23 Mar 2008 15:11:56 -030 |
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?
|
| Post Reply
|
|
|
|
|
|
|
|
|
|