39

I've tried this on both Windows 7 and Windows XP. Start Windows Explorer and create a new folder in some temporary location called (say) NonWriteable. Right-click the folder and set the properties of the folder to Read-only.

Folder set to be read-only

Now open the folder and create a new .txt file. This is allowed. Why? How do you set a folder so that nothing can be modified inside it?

Note: If I right-click the .txt file and set that to Read-only then the system correctly prevents updates to the file.

9
  • 3
    Check the advanced options and actively deny writing permissions. What kind of Account are you using? An administrative Account should always be able to change things.
    – Seth
    Commented Sep 6, 2017 at 10:40
  • @Seth An administrative account should always be able to change things? What if one is trying to access a folder on a different machine? Commented Sep 6, 2017 at 10:47
  • 2
    Windows seems never to have used this setting for directories. If it is within a shared drive you will find that Linux won't be able to create, delete or rename files unless read-only is cleared.
    – AFH
    Commented Sep 6, 2017 at 10:47
  • 2
    @Seth: Good call. After modifying the advanced permissions on the Security tab to deny access to Create Files / Write Data, I now cannot create new files. This seems to be a Windows bug/limitation. If I programmatically call the GetFileAttributes API on the folder, the FILE_ATTRIBUTE_DIRECTORY attribute is set...but not FILE_ATTRIBUTE_READONLY.
    – AlainD
    Commented Sep 6, 2017 at 11:09
  • 2
    Note that starting with Windows 7, the dialog was changed to Read-only (Only applies to files in this folder) to make it more clear what this option actually does. There is a screenshot of the new dialog in this answer. Commented Sep 7, 2017 at 7:21

1 Answer 1

57

Unlike the Read-only attribute for a file, the Read-only attribute for a folder is typically ignored by Windows, Windows components and accessories, and other programs. For example, you can delete, rename, and change a folder with the Read-only attribute by using Windows Explorer.

The Read-only and System attributes is only used by Windows Explorer to determine whether the folder is a special folder, such as a system folder that has its view customized by Windows (for example, My Documents, Favorites, Fonts, Downloaded Program Files), or a folder that you customized by using the Customize tab of the folder's Properties dialog box. As a result, Windows Explorer does not allow you to view or change the Read-only or System attributes of folders. When a folder has the Read-Only attribute set it causes Explorer to request the Desktop.ini of that folder to see if any special folder settings need to be set.

Source: https://support.microsoft.com/en-gb/help/326549/you-cannot-view-or-change-the-read-only-or-the-system-attributes-of-fo

This is an old article but it is still true for all versions of Windows.

To prevent the creation of files in a folder, change the permissions using the Security tab in the folder properties. Click the Advanced button and add a rule to deny access to Create Files / Write Data.

9
  • 1
    @AlainD Yes. It's an old article but it still applies to newer versions of Windows. I'll come back and expand the answer later. Commented Sep 6, 2017 at 11:25
  • 1
    So the "read-only" attribute of a folder has absolutely nothing to do with it being read-only at all? Is it nothing more than a huuuuuge UX failure?
    – Pedro A
    Commented Sep 7, 2017 at 0:30
  • 6
    @Hamsteriffic It's a legacy from a FAT filesystem. FAT used to support only few file attributes, RO being one of them. NTFS features a sophisticated ACL mechanism for access control, so FAT attributes are of no importance when NTFS is employed. However, the particular dialog in question was designed many years ago when FAT was still prevalent and never changed since.
    – oakad
    Commented Sep 7, 2017 at 4:00
  • 4
    @Hamsteriffic So, to sum up oakads comment: Yes. Commented Sep 7, 2017 at 12:58
  • 2
    @jrh He wrote one in 2003 blogs.msdn.microsoft.com/oldnewthing/20030930-00/?p=42353 Commented Sep 7, 2017 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .