How to Change a File to Read Only
When you need to ensure a file isn't changed nether any circumstances in Windows, it'southward time to make information technology read-only. Setting a file as read-but or write-protecting a file prevents any changes whatsoever. If you don't know how to set files as read-only and need to, you're in the correct place!
In this tutorial, yous're going to learn how to set and remove the read-only attribute in File Explorer, the command-line (cmd), and via PowerShell!
Permit'south become going.
Prerequisites
This post will be a easily-on tutorial. If you'd like to follow along, be sure you accept the post-obit:
- A Windows PC. This tutorial will use Windows ten and Windows PowerShell v5.one.
- A file to toggle the read-just attribute on. This tutorial will use a file located at C:\Shared\readme.txt.
How to Make a File Read-Only (and Writable) in File Explorer
There are a few different ways to gear up a file every bit read-simply only allow'south start out this tutorial by first covering how to get in happen via Windows File Explorer.
The read-only attribute is stored every bit a metadata property rather than in the content of the file. The holding tin can be seen through Windows File Explorer.
Bold that y'all're on the desktop of your Windows PC:
1. Open Windows File Explorer and navigate to the folder that stores the file y'all'll be working with (C:\Shared) in this instance.
two. Right click the file and click Properties to open the file's Properties box. This box contains various metadata nigh that particular file such as size, when it was created, modified, etc. Information technology besides has file attributes.
Click the read-just checkbox in the Attributes grouping to write-protect the file or set it as read-only, click Apply to assign the read-just attribute, and OK to close the dialog box.

Similarly, to remove the read-only attribute from the file, uncheck the Read-simply checkbox.
How to Make a File Read-Only (and Writable) via Command Line
File attributes aren't only exposed via File Explorer. You tin can as well dispense file attributes including the read-only attribute via the command line. To do and so, you lot must employ a command called attrib
.
1. Open a command prompt (cmd.exe).
2. Navigate to the folder the file is in.
3. Run attrib
with no parameters. The attrib
command volition immediately look for all files in the working directory and return all files and the enabled file attributes. You tin can see below the readme.txt file does not accept the read-simply attribute enabled.

4. Now, run attrib
to assign the read-only attribute. The +r
parameter is key here. This parameter tells Windows to set the read-only attribute on the file.
5. Run attrib
once more with no parameters to verify the read-just attribute was applied. You lot can now see in the screenshot below the R
characterization shows up indicating the read-just attribute has been applied write-protecting the file.

Similarly, to remove the read-merely aspect utilize the
-r
parameter.
How to Make a File Read-Only (and Writable) with PowerShell
If you're not a fan of the GUI or the command prompt or desire to use have a little more ease of command, look no further than PowerShell! Let's now learn how to make a file read-only with PowerShell!
- Open up Windows PowerShell.
2. Run the Become-Detail
cmdlet providing the path to the file you're toggling the read-just aspect on. The Attributes
belongings returned contains each file attribute that's currently enabled.
get-item -Path "c:\shared\readme.txt" | format-table name, attributes

Using the
Format-Tabular array
cmdlet is non necessary but past doing and then, tells PowerShell to display only the two properties you're interested in in an easy-to-view format (Name
andAttributes
)
3. Assign the read-only attribute by adding the ReadOnly
attribute to the Attributes
belongings as shown below.
## Capture the file object in the $file variable $file = Get-Item -Path "c:\shared\readme.txt" ## Non to overwrite the existing attributes, create a new array containing ## the current file attributes while calculation the ReadOnly aspect and assign ## that array every bit the new value of the Attributes property $file.Attributes = @($file.Attributes,"ReadOnly")

iv. Now, view the Attributes
belongings of the $file
object and you'll see that you've at present applied the ReadOnly
attribute to the file while maintaining any existing attributes that existed on the file beforehand. Yous tin also run Get-Item
again to view the same results.

To remove the ReadOnly
attribute from the file, follow the verbal same arroyo but this time gear up the value of the Attributes
holding to Normal
east.one thousand. $file.Attributes = "Normal"
.
Conclusion
You should now know how to set up a file as read-only and vice versa. Setting a file as read-simply is meant to prevent accidental changes. Simply know that, setting a file as read-merely is non necessarily a security measure and does not prevent access to the file or someone from simply changing the aspect themselves.
Armed with this new cognition of protecting files from existence accidentally overwritten, do yous take any files you'd like to protect?
Source: https://adamtheautomator.com/how-to-make-a-file-read-only/
0 Response to "How to Change a File to Read Only"
Post a Comment