Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Remove the Readonly attribute of a File MFC

Tags:

c++

winapi

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?

like image 242
JijeshKV Avatar asked Oct 27 '11 09:10

JijeshKV


People also ask

How do I remove a file attribute?

Open File Explorer and go to the folder that contains your files. Select the file whose attributes you want to change. On the Home tab of the Ribbon, click on the Properties button. In the next dialog, under Attributes, you can set or remove the Read-only and Hidden attributes.

What is read only attribute?

Read-only is a file attribute which only allows a user to view a file, restricting any writing to the file. Setting a file to “read-only” will still allow that file to be opened and read; however, changes such as deletions, overwrites, edits or name changes cannot be made.


1 Answers

Use SetFileAttributes again to reset the flag:

SetFileAttributes( pszFilename,  
                   GetFileAttributes(pszFilename) & ~FILE_ATTRIBUTE_READONLY);
like image 146
Serge Wautier Avatar answered Sep 24 '22 02:09

Serge Wautier