GetFileAttributes()

Syntax

Attributes = GetFileAttributes(Filename$)
Description
Returns the attributes of the given file.

Parameters

Filename$ The file to read the attributes from. This can also specify the name of a directory.

Return value

Returns the attributes of the file. If the file does not exist or the attributes cannot be read, the result is the value -1.

On Windows, Attributes is a combination of the following values:
  #PB_FileSystem_Hidden    : File is hidden
  #PB_FileSystem_Archive   : File has been changed and not archived since the last time
  #PB_FileSystem_Compressed: File is compressed
  #PB_FileSystem_Normal    : Normal attributes
  #PB_FileSystem_ReadOnly  : File is in read-only mode
  #PB_FileSystem_System    : File is a system file
On Linux or MacOSX, Attributes is a combination of these values:
  #PB_FileSystem_Link      : The file is a symbolic link
  #PB_FileSystem_ReadUser  : Access flags for the owning user
  #PB_FileSystem_WriteUser
  #PB_FileSystem_ExecUser
  #PB_FileSystem_ReadGroup : Access flags for the owning user's group
  #PB_FileSystem_WriteGroup
  #PB_FileSystem_ExecGroup
  #PB_FileSystem_ReadAll   : Access flags for all other users
  #PB_FileSystem_WriteAll
  #PB_FileSystem_ExecAll

Remarks

To check if one attribute is actually set, just use the '&' (binary AND) and the attribute constant value:
  FileAttributes = GetFileAttributes("C:\Text.txt")
  If FileAttributes & #PB_FileSystem_Hidden
    Debug "This file is hidden !"
  EndIf

Example

  Value = GetFileAttributes("c:\autoexec.bat") 
  
  If Value = -1 
    Debug "Error reading file attributes!"
  Else 
    If Value & #PB_FileSystem_Hidden     : txt$ + "H" : Else : txt$+"-" : EndIf 
    If Value & #PB_FileSystem_Archive    : txt$ + "A" : Else : txt$+"-" : EndIf 
    If Value & #PB_FileSystem_Compressed : txt$ + "C" : Else : txt$+"-" : EndIf 
    If Value & #PB_FileSystem_Normal     : txt$ + "N" : Else : txt$+"-" : EndIf 
    If Value & #PB_FileSystem_ReadOnly   : txt$ + "R" : Else : txt$+"-" : EndIf 
    If Value & #PB_FileSystem_System     : txt$ + "S" : Else : txt$+"-" : EndIf 
    Debug txt$ 
  EndIf

See Also

SetFileAttributes(), DirectoryEntryAttributes()

Supported OS

All

<- GetExtensionPart() - FileSystem Index - GetFileDate() ->