2017-04-01 95 views
0

以下代码在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) 

那么,如何创建文件夹,这是不是只读。

回答

0

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

要删除ReadOnly属性,您可以创建一个DirectoryInfo class的实例并修改它的Attributes property。我还强烈建议您在构建路径时使用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. 
+0

右键单击>属性显示我仍然只读? –

+0

@KenKeniee:很奇怪...... TEMP文件夹设置为只读吗?如果使用管理权限运行应用程序会发生什么情况? –

+1

我在这里找到了解决方案:http://stackoverflow.com/questions/14853105/give-folder-full-access-when-created?rq=1 –