How does Read-Only affect a Directory when using C#/.Net?

前端 未结 3 591
南笙
南笙 2021-01-14 08:16

I\'ve found that I can write (say, copy a file into) a Read-Only directory. That is, a Directory with ...Attributes = FileAttributes.ReadOnly.I can even change

3条回答
  •  星月不相逢
    2021-01-14 08:46

    It doesn't. Peel off enough layers, and you'll find the function used to change the attributes on a directory is SetFileAttributes:

    Sets the attributes for a file or directory.

    And note:

    FILE_ATTRIBUTE_READONLY 1 (0x1) A file that is read-only. Applications can read the file, but cannot write to it or delete it. This attribute is not honored on directories. For more information, see "You cannot view or change the Read-only or the System attributes of folders in Windows Server 2003, in Windows XP, or in Windows Vista.

    (My emphasis)

提交回复
热议问题