如何创建非只读文件夹



以下代码在 Temp 文件夹中创建只读文件夹。

System.IO.Directory.CreateDirectory(path:=IO.Path.GetTempPath & "Myfolder")

directorySecurity:=以下代码的一部分需要修复

System.IO.Directory.CreateDirectory(path:=IO.Path.GetTempPath & "Myfolder", directorySecurity:=I need help here)

那么,如何创建非只读的文件夹。

ReadOnly是一个

属性,而不是一个安全选项。虽然默认情况下创建文件夹不应该使其为只读......

若要删除 ReadOnly 属性,可以创建 DirectoryInfo的实例并修改其 Attributes 属性。我还强烈建议您在构造路径时使用Path.Combine()

Dim DirPath As String = Path.Combine(Path.GetTempPath(), "Myfolder")
Directory.CreateDirectory(DirPath)
Dim Dir As New DirectoryInfo(DirPath)
Dir.Attributes = Dir.Attributes And Not FileAttributes.ReadOnly 'Bitwise removal.

最新更新