Doug Harrison [MVP] wrote:
On 28 Mar 2005 06:49:49 -0800, xenny wrote:
Hi,
I'm trying to see if a file (exportfile) is set to read only using
File::GetAttributes:
if ((File::GetAttributes(exportfile.c_str()) &
FileAttributes::ReadOnly) != 0);
{
MessageBox::Show("The File is Read Only","Warning");
}
I've tried that and a few variations but it always returns true.
Any help would be greatly appreciated.
You have an errant semicolon. VC warns about such "empty controlled
statements" at warning level 3 and above.
--
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