Set or Unset Read-only Attribute of Files and Folders in Windows 10  

    Set or Unset Read-only Attribute of Files and Folders in Windows 10

    Set or Unset Read-only Attribute of Files and Folders in Windows 10

    How to Set or Unset Read-only Attribute of Files and Folders in Windows 10
    Published by Category: General Tips
    02 Nov 2023
    Designer Media Ltd

    How to Set or Unset Read-only Attribute of Files and Folders in Windows 10


    In Windows, you can set or unset the read-only attribute for files and folders to give files write protection.

    Folders cannot actual be set as read-only though. Only files in the folder will be set as read-only instead.

    When a file (ex: text file) is set as read-only, the file can no longer be altered since it no longer allows write permission. You will still be able to save your changes to the file as a new file though.

    This tutorial will show you different ways on how to set or unset the read-only attribute of files and folders in Windows 10 and Windows 11.

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-neutral.png Read-only box = Neutral setting of a folder that is always displayed by default.
    Set or Unset Read-only Attribute of Files and Folders in Windows 10-checked.png Read-only box = File is currently read-only. Only displays temporarily for a folder while setting to be applied to files in folder.
    Set or Unset Read-only Attribute of Files and Folders in Windows 10-empty.png Read-only box = File is currently not read-only. Only displays temporarily for a folder while setting to be applied to files in folder.



    Contents

    • Option One: To Set Read-only Attribute of Files and Folders from Properties
    • Option Two: To Unset Read-only Attribute of Files and Folders from Properties
    • Option Three: To Set Read-only Attribute of File using Command Prompt
    • Option Four: To Unset Read-only Attribute of File using Command Prompt
    • Option Five: To Set Read-only Attribute of All Files in Folder and Subfolders using Command Prompt
    • Option Six: To Unset Read-only Attribute of All Files in Folder and Subfolders using Command Prompt
    • Option Seven: To Set Read-only Attribute of File using PowerShell
    • Option Eight: To Unset Read-only Attribute of File using PowerShell
    • Option Nine: To Set Read-only Attribute of All Files in Folder and Subfolders using PowerShell
    • Option Ten: To Unset Read-only Attribute of All Files in Folder and Subfolders using PowerShell



    EXAMPLE: File is set to read-only message
    Set or Unset Read-only Attribute of Files and Folders in Windows 10-read-only_message.png






    OPTION ONE

    To Set Read-only Attribute of Files and Folders from Properties


    1 Open File Explorer (Win+E).

    2 Select one or more files and/or folders you want to set as read-only, right click or press and hold on the selected items, and click/tap on Properties. (see screenshot below)

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-read-only_files_folders_properties.jpg

    3 In the General tab, check the Read-only box in the bottom Attributes section, and click/tap on OK. (see screenshots below)

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-set_read-only_files_folders_properties.jpg

    4 If you selected a folder, select (dot) to either Apply changes to this folder only or Apply changes to this folder, subfolders and files for what you want, and click/tap on OK. (see screenshots below)

    Apply changes to this folder only will only not be grayed out if you selected other files or folders in addition with this folder.

    If you select (dot) Apply changes to this folder only, any selected folders and their contents will be ignored.

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-confrim_set_read-only_files_folders.jpg






    OPTION TWO

    To Unset Read-only Attribute of Files and Folders from Properties


    1 Open File Explorer (Win+E).

    2 Select one or more files and/or folders you want to unset as read-only, right click or press and hold on the selected items, and click/tap on Properties. (see screenshot below)

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-read-only_files_folders_properties.jpg

    3 In the General tab, uncheck the Read-only box in the bottom Attributes section, and click/tap on OK. (see screenshots below)

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-unset_read-only_files_folders_properties.jpg

    4 If you selected a folder, select (dot) to either Apply changes to this folder only or Apply changes to this folder, subfolders and files for what you want, and click/tap on OK. (see screenshots below)

    Apply changes to this folder only will only not be grayed out if you selected other files or folders in addition with this folder.

    If you select (dot) Apply changes to this folder only, any selected folders and their contents will be ignored.

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-confrim_unset_read-only_files_folders.jpg






    OPTION THREE

    To Set Read-only Attribute of File using Command Prompt


    1 Open a command prompt or elevated command prompt based based on the access permissions you have for the file.

    2 Type the command below into the command prompt, and press Enter. (see screenshot below)

    attrib +r "full path of file with extension"

    Substitute full path of file with extension in the command above with the actual full path of the file you want to set as read-only.

    For example: attrib +r "C:\Users\Brink\Desktop\Folder\File1.txt"

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-set_read-only_file_command.png






    OPTION FOUR

    To Unset Read-only Attribute of File using Command Prompt


    1 Open a command prompt or elevated command prompt based based on the access permissions you have for the file.

    2 Type the command below into the command prompt, and press Enter. (see screenshot below)

    attrib -r "full path of file with extension"

    Substitute full path of file with extension in the command above with the actual full path of the file you want to unset as read-only.

    For example: attrib -r "C:\Users\Brink\Desktop\Folder\File1.txt"

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-unset_read-only_file_command.png






    OPTION FIVE

    To Set Read-only Attribute of All Files in Folder and Subfolders using Command Prompt


    1 Open a command prompt or elevated command prompt based based on the access permissions you have for the folder.

    2 Type the command below into the command prompt, and press Enter. (see screenshot below)

    attrib +r "full path of folder\*" /s /d

    Substitute full path of folder in the command above with the actual full path of the folder you want to set read-only for all files in this folder and its subfolders.

    For example: attrib +r "C:\Users\Brink\Desktop\Folder\*" /s /d

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-set_read-only_subfolders_and_files_command.png






    OPTION SIX

    To Unset Read-only Attribute of All Files in Folder and Subfolders using Command Prompt


    1 Open a command prompt or elevated command prompt based based on the access permissions you have for the folder.

    2 Type the command below into the command prompt, and press Enter. (see screenshot below)

    attrib -r "full path of folder\*" /s /d

    Substitute full path of folder in the command above with the actual full path of the folder you want to unset read-only for all files in this folder and its subfolders.

    For example: attrib -r "C:\Users\Brink\Desktop\Folder\*" /s /d

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-unset_read-only_subfolders_and_files_command.png






    OPTION SEVEN

    To Set Read-only Attribute of File using PowerShell


    To see more usage options for the Set-ItemProperty command, see: Set-ItemProperty - Microsoft Docs


    1 Open PowerShell or elevated PowerShell based on the access permissions you have for the file.

    2 Type the command below into PowerShell, and press Enter. (see screenshot below)

    Set-ItemProperty -Path "full path of file with extension" -Name IsReadOnly -Value $True

    Substitute full path of file with extension in the command above with the actual full path of the file you want to set as read-only.

    For example: Set-ItemProperty -Path "C:\Users\Brink\Desktop\Folder\File1.txt" -Name IsReadOnly -Value $True

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-set_read-only_file_powershell.png






    OPTION EIGHT

    To Unset Read-only Attribute of File using PowerShell


    To see more usage options for the Set-ItemProperty command, see: Set-ItemProperty - Microsoft Docs


    1 Open PowerShell or elevated PowerShell based on the access permissions you have for the file.

    2 Type the command below into PowerShell, and press Enter. (see screenshot below)

    Set-ItemProperty -Path "full path of file with extension" -Name IsReadOnly -Value $False

    Substitute full path of file with extension in the command above with the actual full path of the file you want to unset as read-only.

    For example: Set-ItemProperty -Path "C:\Users\Brink\Desktop\Folder\File1.txt" -Name IsReadOnly -Value $False

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-unset_read-only_file_powershell.png






    OPTION NINE

    To Set Read-only Attribute of All Files in Folder and Subfolders using PowerShell


    To see more usage options for the Get-ChildItem command, see: Get-ChildItem - Microsoft Docs


    1 Open PowerShell or elevated PowerShell based on the access permissions you have for the folder.

    2 Type the command below into PowerShell, and press Enter. (see screenshot below)

    Get-ChildItem -Path "full path of file with extension" -Recurse -File | % { $_.IsReadOnly=$True }

    Substitute full path of file with extension in the command above with the actual full path of the folder you want to set read-only for all files in this folder and its subfolders.

    For example: Get-ChildItem -Path "C:\Users\Brink\Desktop\Folder\File1.txt" -Recurse -File | % { $_.IsReadOnly=$True }

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-set_read-only_subfolders_and_files_powershell.png






    OPTION TEN

    To Unset Read-only Attribute of All Files in Folder and Subfolders using PowerShell


    To see more usage options for the Get-ChildItem command, see: Get-ChildItem - Microsoft Docs


    1 Open PowerShell or elevated PowerShell based on the access permissions you have for the folder.

    2 Type the command below into PowerShell, and press Enter. (see screenshot below)

    Get-ChildItem -Path "full path of file with extension" -Recurse -File | % { $_.IsReadOnly=$False }

    Substitute full path of file with extension in the command above with the actual full path of the folder you want to unset read-only for all files in this folder and its subfolders.

    For example: Get-ChildItem -Path "C:\Users\Brink\Desktop\Folder\File1.txt" -Recurse -File | % { $_.IsReadOnly=$False }

    Set or Unset Read-only Attribute of Files and Folders in Windows 10-unset_read-only_subfolders_and_files_powershell.png


    That's it,
    Shawn Brink






  1. Posts : 1
    Windows 10
       #1

    Alternative script for files and folders


    Many of these scripts worked for files or folders but none of them handled files and folders as a single script. This powershell script removed the ReadOnly property or attribute for both files and folders.
    Code:
    Get-ChildItem -Path  "C:\Temp" -Recurse | foreach {
        if ($_.PSisContainer) {
            $fn = $_.FullName
            $folder = Get-Item $fn
            $prevstate = $folder.Attributes -match 'ReadOnly'
            if ($prevstate) {
                Write-Host 'the fold is     readonly ' $fn
                $folder.Attributes -= 'ReadOnly'
                $state = $folder.Attributes -match 'ReadOnly'
                if ($state -eq $prevstate) {
                    Write-Host 'ERROR the fold is still readonly ' $fn
                }
                else {
                    Write-Host 'the fold is NOT readonly ' $fn
                }
            }
        }
        else {
            $fn = $_.FullName
            $prevstate = Get-ItemPropertyValue -Path $fn -Name IsReadOnly
            if ($prevstate) {
                Write-Host 'the file is    readonly ' $fn
                Set-ItemProperty -Path $fn -Name IsReadOnly -Value $true
                $state = Get-ItemPropertyValue -Path $fn -Name IsReadOnly
                if ($state -eq $prevstate) {
                    Write-Host 'ERROR the file is still readonly ' $fn
                }
                else {
                    Write-Host 'the file is NOT readonly ' $fn
                }
            }
        }
    }
      My Computer


 

Tutorial Categories

Set or Unset Read-only Attribute of Files and Folders in Windows 10 Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:34.
Find Us




Windows 10 Forums