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

前端 未结 3 588
南笙
南笙 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:19

    The read-only attribute on a directory entry in the file system has limited usefulness. Most any user would expect all the files in the directory to become read-only as well. But that's not how NTFS works, attributes only apply to the file system object itself and are not "inherited" like the security attributes are.

    Note how Explorer modified the way the attribute works in its UI, when you turn it on then it does what any user expects, it makes all the files read-only instead of setting the attribute on the directory itself.

    But yes, it does work, it prevents modifications to the directory object itself. So if you turn it on in code then that does prevent deleting the directory. Just as it does with a file.

提交回复
热议问题