Thread View: borland.public.cppbuilder.nativeapi
6 messages
6 total messages
Started by Sky
Tue, 06 May 2003 11:52
How to conclude a file or directory exists
Author: Sky
Date: Tue, 06 May 2003 11:52
Date: Tue, 06 May 2003 11:52
7 lines
1096 bytes
1096 bytes
hi all, I want to know whether a file or directory is existed or not? not use VCL, I know the FileExists/DirectoryExists in VCL. great appreciated if any hint. Sky 2003-5-6
Re: How to conclude a file or directory exists
Author: Nick B. Cassos
Date: Tue, 06 May 2003 13:07
Date: Tue, 06 May 2003 13:07
40 lines
1882 bytes
1882 bytes
On Tue, 6 May 2003 19:52:54 +0800, "Sky" <akeehuang@163.net> wrote:
>hi all,
>I want to know whether a file or directory is existed or not?
>not use VCL, I know the FileExists/DirectoryExists in VCL.
bool __fastcall MyDirExists(const AnsiString ADir)
{
bool Result = false;
DWORD AAttr = ::GetFileAttributes(ADir.c_str());
if (AAttr != 0xFFFFFFFF)
{
if ((AAttr & FILE_ATTRIBUTE_DIRECTORY) != 0)
Result = true;
}
return Result;
}
bool __fastcall MyFileExists(const AnsiString AFile)
{
bool Result = false;
WIN32_FIND_DATA FD;
HANDLE Handle = FindFirstFile(AFile.c_str(),&FD);
if (Handle != INVALID_HANDLE_VALUE)
{
::FindClose(Handle);
if ((FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
Result = true;
}
return Result;
}
--
Nick B. Cassos
Re: How to conclude a file or directory exists
Author: HuangC
Date: Tue, 06 May 2003 15:21
Date: Tue, 06 May 2003 15:21
1 lines
1029 bytes
1029 bytes
Thanks!
Re: How to conclude a file or directory exists
Author: Greg Brewer
Date: Tue, 06 May 2003 23:21
Date: Tue, 06 May 2003 23:21
59 lines
2832 bytes
2832 bytes
There are possible problems with this answer.
First, you need to test the string for the presence of * or ?. If either of
those characters exist then you may get what amounts to a false positive.
Also, watch out for filenames such as nul, prn, con, etc.
Second, you may have problems with network drives. I have had problems with
them and I never found a satisfactory solution. On the network I was
working on, a particular test would work; however, I would get false
positives on my customer's network. Some networks identified a file as
existing when it didn't. Some identified a folder as a file. It was messy.
I'm afraid I do not remember the particulars of what I had trouble with and
what I did to fix it.
Greg
"Nick B. Cassos" <nbc@no_spam.ath.forthnet.gr> wrote in message
news:encfbvo8rr3i96t9llc1mbo2917lb8vhda@4ax.com...
> On Tue, 6 May 2003 19:52:54 +0800, "Sky" <akeehuang@163.net> wrote:
>
> >hi all,
> >I want to know whether a file or directory is existed or not?
> >not use VCL, I know the FileExists/DirectoryExists in VCL.
>
> bool __fastcall MyDirExists(const AnsiString ADir)
> {
> bool Result = false;
> DWORD AAttr = ::GetFileAttributes(ADir.c_str());
>
> if (AAttr != 0xFFFFFFFF)
> {
> if ((AAttr & FILE_ATTRIBUTE_DIRECTORY) != 0)
> Result = true;
> }
>
> return Result;
> }
>
> bool __fastcall MyFileExists(const AnsiString AFile)
> {
> bool Result = false;
> WIN32_FIND_DATA FD;
> HANDLE Handle = FindFirstFile(AFile.c_str(),&FD);
>
> if (Handle != INVALID_HANDLE_VALUE)
> {
> ::FindClose(Handle);
>
> if ((FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
> Result = true;
> }
>
> return Result;
> }
>
> --
>
> Nick B. Cassos
Re: How to conclude a file or directory exists
Author: JD
Date: Wed, 07 May 2003 01:16
Date: Wed, 07 May 2003 01:16
16 lines
1385 bytes
1385 bytes
"Sky" <akeehuang@163.net> wrote:
> [...] a file or directory is existed or not? not use VCL,
Use access:
access: determines accessibility of a file
int access(const char *filename, int amode);
amode = 0 checks for file existence
amode = 2 checks for write permission
If the requested access is allowed, 0 is returned; otherwise, a
value of -1 is returned and errno is set.
~ JD
Re: How to conclude a file or directory exists
Author: StarCinema - Rodolfo Frino
Date: Wed, 07 May 2003 22:38
Date: Wed, 07 May 2003 22:38
20 lines
1465 bytes
1465 bytes
I think the simplest (and portable) way of doing that is via the method described by JD Alternatively you can use this code http://www.geocities.com/rodolfofrino/FileExists.html which also works under UNIX Rodolfo Stargate Software "Sky" <akeehuang@163.net> wrote in message news:3eb7a237@newsgroups.borland.com... > hi all, > I want to know whether a file or directory is existed or not? > not use VCL, I know the FileExists/DirectoryExists in VCL. > great appreciated if any hint. > > Sky > 2003-5-6 > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads