| GetAttr Function |
Named Arguments
No
Syntax
GetAttr(pathname)
pathname
Use: Required
Data Type: String
File and optional path name.
Return Value
An integer representing the attributes set for the file or folder, being the sum of the following constant values:
| Constant | Value | Description |
|---|---|---|
| vbNormal | 0 | Normal |
| vbReadOnly | 1 | Read-only |
| vbHidden | 2 | Hidden |
| vbSystem | 4 | System |
| vbDirectory | 16 | Directory or folder |
| vbArchive | 32 | File has changed since last backup |
Description
Determines which attributes have been set for a file, directory, or folder.
Rules at a Glance
pathname may optionally include a directory or folder 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 bit-wise comparison of the GetAttr return value and the value of the attribute constant using the And 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
The file attribute constants are defined to be globally available for use within your projects.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access