Attributes Property

Applies to TestComplete 14.80, last modified on April 15, 2021

Description

Use the Attributes property to determine the attributes of the specified file.

Declaration

aqFileInfoObj.Attributes

Read-Only Property Integer
aqFileInfoObj An expression, variable or parameter that specifies a reference to an aqFileInfo object

Applies To

The property is applied to the following object:

Property Value

An interger value that indicates the attributes of the given file. The method can return one or a combination of constants listed in the following table (these constants are defined in the aqFileSystem object). Multiple values are combined using the bitwise OR operator.

Constant Value Description
faReadOnly 1 A read-only file.
faHidden 2 A hidden file.
faSystem 4 A system file.
faArchive 32 An archive file.
faNormal 128 A normal file (that is, a file without any other attributes set).
faTemporary 256 A temporary file.
faSparseFile 512 A sparse file.
faReparsePoint 1024 A link or shortcut file, or a file that has an associated reparse point.
faCompressed 2048 A compressed file.
faOffline 4096 A file whose data is physically moved to offline storage.
faNotContentIndexed 8192 A file that is not indexed by the content indexing service.
faEncrypted 16384 An encrypted file.
faVirtual 65536 A virtual file.

Remarks

To check if a file has a specific attribute set, perform the bitwise AND check on the Attribute property value and the value corresponding to the desired attribute (see the example below). Alternatively, you can use the aqFileSystem.CheckAttributes method.

Example

The following example checks if a file has the read-only attribute set:

JavaScript, JScript

function Test()
{
  var attr = aqFileSystem.GetFileInfo("C:\\MyFile.txt").Attributes;

  if ((attr & aqFileSystem.faReadOnly) == aqFileSystem.faReadOnly)
    Log.Message("The file is read-only.")
  else
    Log.Message("The file is not read-only.");
}

Python

def Test():
  attr = aqFileSystem.GetFileInfo("C:\\MyFiles\\MyFile.txt").Attributes
  if attr & aqFileSystem.faReadOnly == aqFileSystem.faReadOnly:
    Log.Message("The file is read-only.")
  else:
    Log.Message("The file is not read-only.")

VBScript

Sub Test
  Dim attr

  attr = aqFileSystem.GetFileInfo("C:\MyFile.txt").Attributes

  If (attr And aqFileSystem.faReadOnly) = aqFileSystem.faReadOnly Then
    Log.Message("The file is read-only.")
  Else
    Log.Message("The file is not read-only.")
  End If
End Sub

DelphiScript

procedure Test;
var attr;
begin
  attr := aqFileSystem.GetFileInfo('C:\MyFile.txt').Attributes;

  if (attr and aqFileSystem.faReadOnly) = aqFileSystem.faReadOnly then
    Log.Message('The file is read-only.')
  else
    Log.Message('The file is not read-only.');
end;

C++Script, C#Script

function Test()
{
  var attr = aqFileSystem["GetFileInfo"]("C:\\MyFile.txt")["Attributes"];

  if ((attr & aqFileSystem["faReadOnly"]) == aqFileSystem["faReadOnly"])
    Log["Message"]("The file is read-only.")
  else
    Log["Message"]("The file is not read-only.");
}

The following example checks if a file has both the read-only and hidden attributes set:

JavaScript, JScript

function Test()
{
  var attr = aqFileSystem.GetFileInfo("C:\\MyFile.txt").Attributes;
  var faReadOnlyHidden = aqFileSystem.faReadOnly | aqFileSystem.faHidden;

  if ((attr & faReadOnlyHidden) == faReadOnlyHidden)
    Log.Message("The file is read-only and hidden.")
  else
    Log.Message("The file is not read-only and/or not hidden.");
}

Python

def Test1():
  attr = aqFileSystem.GetFileInfo("C:\\MyFiles\\MyFile.txt").Attributes
  faReadOnlyHidden = aqFileSystem.faReadOnly | aqFileSystem.faHidden
  if attr & faReadOnlyHidden == faReadOnlyHidden:
    Log.Message("The file is read-only and hidden.")
  else:
    Log.Message("The file is not read-only and/or not hidden.")

VBScript

Sub Test
  Dim attr, faReadOnlyHidden

  attr = aqFileSystem.GetFileInfo("C:\MyFile.txt").Attributes
  faReadOnlyHidden = aqFileSystem.faReadOnly Or aqFileSystem.faHidden

  If (attr And faReadOnlyHidden) = faReadOnlyHidden Then
    Log.Message("The file is read-only and hidden.")
  Else
    Log.Message("The file is not read-only and/or not hidden.")
  End If
End Sub

DelphiScript

procedure Test;
var faReadOnlyHidden, attr;
begin
  faReadOnlyHidden := aqFileSystem.faReadOnly or aqFileSystem.faHidden;
  attr := aqFileSystem.GetFileInfo('C:\MyFile.txt').Attributes;

  if (attr and faReadOnlyHidden) = faReadOnlyHidden then
    Log.Message('The file is read-only and hidden.')
  else
    Log.Message('The file is not read-only and/or not hidden.');
end;

C++Script, C#Script

function Test()
{
  var attr = aqFileSystem["GetFileInfo"]("C:\\MyFile.txt")["Attributes"];
  var faReadOnlyHidden = aqFileSystem["faReadOnly"] | aqFileSystem["faHidden"];

  if ((attr & faReadOnlyHidden) == faReadOnlyHidden)
    Log["Message"]("The file is read-only and hidden.")
  else
    Log["Message"]("The file is not read-only and/or not hidden.");
}

See Also

Working With Files From Scripts
CheckAttributes Method
ChangeAttributes Method
GetFileInfo Method
GetFileAttributes Method
SetFileAttributes Method
Attributes Property

Highlight search results