Name
GetAttr Function
Class
Microsoft. VisualBasic.FileSystem
Yes
Syntax
GetAttr(pathname
)
-
pathname
Use: Required
Data Type: String
Filename and an optional pathname
Return Value
An integer representing the sum of the following constants or members
of the FileAttribute
enumeration, which reflect
the attributes set for the file:
FileAttribute Enum |
Constant |
Value |
Description |
---|---|---|---|
Normal |
|
0 |
Normal |
ReadOnly |
|
1 |
Read-only |
Hidden |
|
2 |
Hidden |
System |
|
4 |
System |
Directory |
|
16 |
Directory or folder |
Archive |
|
32 |
File has changed since last backup |
Description
Determines which attributes have been set for a file or directory
Rules at a Glance
pathname
may optionally include a directory name and a drive letter, including a network drive.pathname
can also follow the UNC format of//machine_name/drive
.You can check if a particular attribute has been set by performing a bitwise comparison of the
GetAttr
return value and the value of the attribute constant using theAnd
operator. A nonzero result means that the particular attribute has been set; conversely, a zero value indicates that the attribute has not been set. For example:If (GetAttr(myfile.txt) And VbReadOnly) = 0 then Msgbox "The file is Read-Write" Else MsgBox "The file is Read-Only" End If
Programming Tips and Gotchas
If pathname
is invalid, a
FileNotFoundException exception is generated.
Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.