
Signature
Doug Harrison
Microsoft MVP - Visual C++
> > Hi,
> >
[quoted text clipped - 17 lines]
> Doug Harrison
> Microsoft MVP - Visual C++
O yeah, good point :-)
But even if I remove that it still does the same thing.
But, I've found a way to make it work:
FileAttributes fa = File::GetAttributes(exportfile.c_str());
if ((fa == ReadOnly) || (fa % 2 == 1))
{
MessageBox::Show("The File is Read Only","Warning");
}
Now that will only show the message box when the file is read only.
And will work even if the file has other attributes as well as the read
only (the second part of the if statement).
Cheers.
Chris
Doug Harrison [MVP] - 28 Mar 2005 19:39 GMT
> O yeah, good point :-)
>
[quoted text clipped - 12 lines]
> And will work even if the file has other attributes as well as the read
> only (the second part of the if statement).
That's not how to do it. The following should work:
FileAttributes attr = File::GetAttributes(exportfile.c_str());
if (attr == -1)
{
// error
}
else if (attr & FileAttributes::ReadOnly)
{
// File is readonly
}
You have to check it against -1 because that's what GetAttributes returns
in case of error, e.g. a file that doesn't exist.

Signature
Doug Harrison
Microsoft MVP - Visual C++
Severian - 28 Mar 2005 19:50 GMT
>> > Hi,
>> >
[quoted text clipped - 34 lines]
>And will work even if the file has other attributes as well as the read
>only (the second part of the if statement).
All you need is:
if (fa & ReadOnly) {
}
or
if (File::GetAttributes(exportfile.c_str()) & ReadOnly) {
}
--
Sev