How to remove read-only attribute of a folder by powershell?

Question:

I have tried many code but still I am not able to remove read-only property of that particular folder.

Below is the code which removes read-only property of the files present under that folder but does not remove read-only attribute of that Folder :

Answer:

Whether a folder has the ReadOnly attribute set or not, can be verified with:

Default output will be:

Directory

To add the ReadOnly attribute, just execute:

If you display the attributes again, it should look like this:

ReadOnly, Directory

To remove the ReadOnly attribute, just execute:

The attributes look like that again:

Directory

As you can see, it is indeed possible to add and remove the ReadOnly attribute, but as others already mentioned in the comments, it won’t have much of an effect.


The ReadOnly attribute can also be added and/or removed in a more readable way:

But be aware, that this does not work reliably, if you add the attribute when it already exists or if you remove it when it does not exist. This is because the attributes are stored in a bit field. Subtracting an unset bit will flip many other bits instead of just this one bit.

Source:

How to remove read-only attribute of a folder by powershell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply