SetAttr Statement

為指定的檔案設定屬性資訊。

Syntax:


SetAttr PathName As String, Attributes As Integer

Parameters:

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:

Named constant

Value

Definition

ATTR_NORMAL

0

Normal files.

ATTR_READONLY

1

Read-only files.

ATTR_HIDDEN

2

Hidden file


您可以透過邏輯「或」陳述式來組合各值,以設定多個屬性。

錯誤代碼:

5 無效的程序呼叫

53 找不到檔案

70 存取遭拒

Example:


Sub ExampleSetGetAttr
 On Error Goto ErrorHandler REM 定義錯誤處理程式的目標
 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

Please support us!