Article View: borland.public.cppbuilder.nativeapi
Article #9040Re: How to indicate the security property for a file/dir
From: Vladimir Stefanovic
Date: Fri, 06 Aug 2004 16:09
Date: Fri, 06 Aug 2004 16:09
68 lines
2200 bytes
2200 bytes
You can sometimes check the file BEFORE you take action,
and sure you can take actions AFTER an unsuccessful try.
These are some functions that I sometimes use BEFORE I
take some action:
bool IsFileOccupied( const char* s )
{
try
{
TFileStream *tStream = new TFileStream( AnsiString( s ),
fmOpenRead|fmShareExclusive );
delete tStream;
return( false );
}
catch (...)
{
return( true );
}
}
bool CheckIfFileExists( const char* s )
{
return access( s, 0 ) == 0;
}
bool IsFileReadOnly( const char* s )
{
return access( s, 02 ) != 0;
}
bool IsFileReadable( const char* AFilename )
{
FILE *fp;
fp = fopen( AFilename, "r" );
if ( fp == 0 )
return ( false );
else
{
fclose( fp );
return ( true );
}
}
bool IsFileWritable(const char* fileName)
{
if ( access( fileName, 02 ) == 0)
return ( true );
if ( errno == ENOENT ) // we know now it doesnt exist
{
FILE *fp = fopen( fileName, "a" );
if ( fp )
{
fclose( fp );
unlink( fileName );
return ( true );
}
}
return ( false );
}
Best regards,
Vladimir Stefanovic
Technical Details
Message-ID:
<4113ad4b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4112d83b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f0db0b6c7fd04e28 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Vladimir Stefanovic" <spam@not.needed> Newsgroups: borland.public.cppbuilder.nativeapi References: <4112d83b@newsgroups.borland.com> Subject: Re: How to indicate the security property for a file/dir Date: Fri, 6 Aug 2004 18:09:43 +0200 Lines: 71 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 NNTP-Posting-Host: 213.137.116.133 Message-ID: <4113ad4b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1091808587 213.137.116.133 (6 Aug 2004 09:09:47 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail