Create a Read-only Copy of a File Somewhere Else in File System Windows

When you need to ensure a file isn't inverse nether any circumstances in Windows, it's time to make it read-only. Setting a file equally read-only or write-protecting a file prevents any changes whatever. If you don't know how to set up files equally read-just and need to, you're in the right place!

In this tutorial, you're going to learn how to set and remove the read-but attribute in File Explorer, the control-line (cmd), and via PowerShell!

Permit's get going.

Prerequisites

This mail service will be a easily-on tutorial. If you'd like to follow along, be sure you lot accept the following:

  • A Windows PC. This tutorial will use Windows 10 and Windows PowerShell v5.1.
  • 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 unlike ways to set up a file as read-only simply let's start out this tutorial by first covering how to arrive happen via Windows File Explorer.

The read-merely aspect is stored as a metadata holding rather than in the content of the file. The property can exist seen through Windows File Explorer.

Assuming that you're on the desktop of your Windows PC:

1. Open Windows File Explorer and navigate to the binder that stores the file you lot'll be working with (C:\Shared) in this instance.

two. Correct click the file and click Backdrop to open the file's Backdrop box. This box contains various metadata about that particular file such equally size, when it was created, modified, etc. It also has file attributes.

Click the read-only checkbox in the Attributes group to write-protect the file or set up it as read-but, click Employ to assign the read-but attribute, and OK to close the dialog box.

The properties box of the file readme.txt. Note the location of the Read-only attribute check box and the Apply button.
The properties box of the file readme.txt. Note the location of the Read-just attribute check box and the Utilise button.

Similarly, to remove the read-simply attribute from the file, uncheck the Read-simply checkbox.

How to Make a File Read-Only (and Writable) via Control Line

File attributes aren't but exposed via File Explorer. You can also manipulate file attributes including the read-only attribute via the command line. To practise so, you must use a control called attrib.

1. Open up a control prompt (cmd.exe).

ii. Navigate to the binder the file is in.

3. Run attrib with no parameters. The attrib control volition immediately look for all files in the working directory and render all files and the enabled file attributes. You lot can see beneath the readme.txt file does non have the read-only attribute enabled.

Archive attribute enabled (A) but no read-only attribute (R)
Archive aspect enabled (A) but no read-only attribute (R)

iv. Now, run attrib to assign the read-simply aspect. The +r parameter is key hither. This parameter tells Windows to set the read-but attribute on the file.

v. Run attrib again with no parameters to verify the read-only attribute was applied. You can now see in the screenshot beneath the R label shows up indicating the read-but aspect has been applied write-protecting the file.

Read-only attribute (R) is now enabled
Read-just attribute (R) is now enabled

Similarly, to remove the read-only attribute employ the -r parameter.

How to Make a File Read-Simply (and Writable) with PowerShell

If you lot're not a fan of the GUI or the command prompt or want to use have a petty more than ease of control, look no farther than PowerShell! Allow'due south now learn how to make a file read-simply with PowerShell!

  1. Open up Windows PowerShell.

2. Run the Get-Detail cmdlet providing the path to the file you're toggling the read-only attribute on. The Attributes belongings returned contains each file attribute that's currently enabled.

            get-item -Path "c:\shared\readme.txt" | format-table proper name, attributes          
The Archive attribute is only enabled.
The Archive attribute is only enabled.

Using the Format-Table cmdlet is not necessary simply by doing so, tells PowerShell to brandish just the two properties you're interested in in an easy-to-view format (Proper name and Attributes)

three. Assign the read-simply attribute by adding the ReadOnly attribute to the Attributes property as shown below.

            ## Capture the file object in the $file variable  $file = Get-Detail -Path "c:\shared\readme.txt" ## Not to overwrite the existing attributes, create a new array containing ## the electric current file attributes while adding the ReadOnly attribute and assign ## that assortment as the new value of the Attributes property  $file.Attributes = @($file.Attributes,"ReadOnly")          
Assigning the Read Only Attribute
Assigning the Read Only Aspect

4. At present, view the Attributes holding of the $file object and y'all'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. Y'all tin can also run Get-Item again to view the same results.

Viewing the Attribute Property
Viewing the Attribute Property

To remove the ReadOnly aspect from the file, follow the verbal same approach only this time set the value of the Attributes property to Normal e.g. $file.Attributes = "Normal".

Conclusion

You should at present know how to set a file every bit read-only and vice versa. Setting a file as read-only is meant to prevent accidental changes. But know that, setting a file as read-only is non necessarily a security measure out and does not prevent access to the file or someone from simply irresolute the aspect themselves.

Armed with this new knowledge of protecting files from being accidentally overwritten, exercise you accept any files you lot'd similar to protect?

bryantzies1983.blogspot.com

Source: https://adamtheautomator.com/how-to-make-a-file-read-only/

0 Response to "Create a Read-only Copy of a File Somewhere Else in File System Windows"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel