How to Remove the Readonly attribute of a File MFC

11,440

Use SetFileAttributes again to reset the flag:

SetFileAttributes( pszFilename,  
                   GetFileAttributes(pszFilename) & ~FILE_ATTRIBUTE_READONLY);
Share:
11,440
JijeshKV
Author by

JijeshKV

Updated on June 05, 2022

Comments

  • JijeshKV
    JijeshKV almost 2 years

    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?

  • Alexis Wilke
    Alexis Wilke over 11 years
    GetFileAttributes() may returned many other flags that the SetFileAttributes() function doesn't understand, is that safe? Will those extra flag be ignored?
  • paulm
    paulm about 11 years
    2nd call has a typo, File not Files :)
  • Serge Wautier
    Serge Wautier about 11 years
    @paulm: Feel free to fix it. That's why SO is a wiki! OK, did it.
  • paulm
    paulm about 11 years
    I'd love to, but it says changing 1 char is not enough and won't accept the edit.