11

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?

Deanna
  • 23,400
  • 7
  • 68
  • 152
JijeshKV
  • 660
  • 2
  • 7
  • 26
  • 1
    Don't you just GetFileAttributes, mask off the flag (flags &=~READ_ONLY) and SetFileAttributes again? – Rup Oct 27 '11 at 09:26
  • Thanks For the Comment... but not clear... Will u please explain (if u don't mind an example will be more helpful) – JijeshKV Oct 27 '11 at 10:26
  • I assumed that wasn't too much different from what you were already doing to set it read only in the first place! But glad to see Serge has helped you - you should click the tick next to his answer since it solved your problem. – Rup Oct 27 '11 at 17:06
  • @Rup Sorry I am not so familiar in such activities... Thnaks for the Helpful comment – JijeshKV Oct 31 '11 at 06:59

1 Answers1

26

Use SetFileAttributes again to reset the flag:

SetFileAttributes( pszFilename,  
                   GetFileAttributes(pszFilename) & ~FILE_ATTRIBUTE_READONLY);
Serge Wautier
  • 20,884
  • 13
  • 66
  • 107