aqFile.GetFileAttributes Method

Applies to TestComplete 14.40, last modified on April 22, 2021

Description

Use the GetFileAttributes method to find the attributes of the specified file. To change the attributes of a file, use the aqFile.SetFileAttributes method.

Declaration

aqFile.GetFileAttributes(PathToFile)

PathToFile [in]    Required    String    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

PathToFile

Specifies the fully-qualified path to the desired file.

Result Value

An integer value that indicates the attributes of the 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 method’s return 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 = aqFile.GetFileAttributes("C:\\MyFile.txt");

  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 = aqFile.GetFileAttributes("C:\\MyFiles\\MyFile.txt")
  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 = aqFile.GetFileAttributes("C:\MyFile.txt")

  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 := aqFile.GetFileAttributes('C:\MyFile.txt');

  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 = aqFile["GetFileAttributes"]("C:\\MyFile.txt");

  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 = aqFile.GetFileAttributes("C:\\MyFile.txt");
  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 Test2():
  attr = aqFile.GetFileAttributes("C:\\MyFiles\\MyFile.txt");
  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 = aqFile.GetFileAttributes("C:\MyFile.txt")
  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;
const faReadOnlyHidden = aqFileSystem.faReadOnly or aqFileSystem.faHidden;
var attr;
begin
  attr := aqFile.GetFileAttributes('C:\MyFile.txt');

  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 = aqFile["GetFileAttributes"]("C:\\MyFile.txt");
  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
SetFileAttributes Method
Attributes Property
Attributes Property

Highlight search results