SetAttr 语句

设置指定文件的属性信息。

语法:


SetAttr PathName As String, Attributes As Integer

参数:

FileName: Name of the file, including the path, that you want to test attributes of. If you do not enter a path, SetAttr searches for the file in the current directory. You can also use URL notation.

Attributes: Bit pattern defining the attributes that you want to set or to clear:

已命名的常量

定义

ATTR_NORMAL

0

普通文件。

ATTR_READONLY

1

只读文件。

ATTR_HIDDEN

2

隐藏的文件


用逻辑 OR 语句组合相应的值,您可以设置多种属性。

错误代码:

5 无效的过程调用

53 未找到文件

70 权限被拒绝

示例:


Sub ExampleSetGetAttr
 On Error GoTo ErrorHandler ' 定义错误处理程序的目标
 If Dir("C:\test",16)="" Then MkDir "C:\test"
 If Dir("C:\test\autoexec.sav")="" Then FileCopy "c:\autoexec.bat", "c:\test\autoexec.sav"
 SetAttr "c:\test\autoexec.sav" ,0
 FileCopy "c:\autoexec.bat", "c:\test\autoexec.sav"
 SetAttr "c:\test\autoexec.sav" , ATTR_READONLY
 Print GetAttr( "c:\test\autoexec.sav" )
 End
ErrorHandler:
 Print Error
 End
End Sub

请支持我们!