简体   繁体   English

使用vb.net设置文件属性

[英]using vb.net to set file attributes

I would like to know how can I set attributes for a file in vb.net 我想知道如何在vb.net中设置文件的属性

when I open command prompt and I type this I can set attrib 当我打开命令提示符并键入此命令时,可以设置属性

attrib +a +h +s test.txt

how exactly do I do this on vb.net 我怎么在vb.net上做到这一点

Try this: 尝试这个:

File.SetAttributes(path, File.GetAttributes("test.txt") Or FileAttributes.Archive)
File.SetAttributes(path, File.GetAttributes("test.txt") Or FileAttributes.Hidden)
File.SetAttributes(path, File.GetAttributes("test.txt") Or FileAttributes.System)

Private Sub GAttrib (fpath As String) 私有子GAttrib(fpath作为字符串)

'To get attributes: 'fpath must contain the full path and file name ex: C:\\Test.txt MsgBox(File.GetAttributes(fpath).ToString) '要获取属性:'fpath必须包含完整路径和文件名,例如:C:\\ Test.txt MsgBox(File.GetAttributes(fpath).ToString)

To set/change attributes: File.SetAttributes(fpath, FileAttributes.Archive Or FileAttributes.Hidden Or FileAttributes.System Or FileAttributes.ReadOnly) 设置/更改属性:File.SetAttributes(fpath,FileAttributes.Archive或FileAttributes.Hidden或FileAttributes.System或FileAttributes.ReadOnly)

'You can use a single attribute or a combination like above. '您可以使用单个属性或上述组合。 'If you want to check the new attribute(s) repeat the msgbox MsgBox(File.GetAttributes(fpath).ToString) '如果要检查新属性,请重复msgbox MsgBox(File.GetAttributes(fpath).ToString)

End Sub 结束子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM