JijeshKV
JijeshKV

Reputation: 670

How to Remove the Readonly attribute of a File MFC

In my MFC application I have set the read only attribute on a particular file. I have done this by using the SetFileAttributes() function. At some point I have to remove that attribute of that file again.

Can anyone explain how to do this?

Upvotes: 12

Views: 13095

Answers (1)

Serge Wautier
Serge Wautier

Reputation: 21898

Use SetFileAttributes again to reset the flag:

SetFileAttributes( pszFilename,  
                   GetFileAttributes(pszFilename) & ~FILE_ATTRIBUTE_READONLY);

Might be worth adding that this method returns 0 if the function fails and you can use GetLastError().

Upvotes: 28

Related Questions