SetAttributes Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use the SetAttributes method to change the attributes of the folder to which the aqFolderInfoObj object provides access. To obtain the existing folder’s attributes, use the aqFolderInfo.Attributes property.

Declaration

aqFolderInfoObj.SetAttributes(fAttr)

aqFolderInfoObj An expression, variable or parameter that specifies a reference to an aqFolderInfo object
fAttr [in]    Required    Integer    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

fAttr

An integer value that specifies the folder’s new attributes. It can accept one constant or a combination of constants listed in the following table (these constants are defined in the aqFileSystem object). To combine multiple values, use the bitwise OR operator.

Constant Value Description
faReadOnly 1 A read-only folder.
faHidden 2 A hidden folder.
faSystem 4 A system folder.
faDirectory 16 A folder.
faArchive 32 An archive folder.
faNormal 128 A folder that does not have any other attributes set.
faOffline 4096 A folder whose content is physically moved to an offline storage.
NotContentIndexed 8192 A folder that is not to be indexed by the content indexing service.

Result Value

If the folder attributes have been changed successfully, the method returns 0. Otherwise, it returns a Windows error code. To get the error description, use the aqUtils.SysErrorMessage method. For the complete list of error codes, refer to the System Error Codes article in the MSDN library.

Remarks

The aqFolderInfo.SetAttributes method is not recursive. To change folder attributes recursively, you need to explicitly set the attributes for all the files and subfolders in that folder.

The following attributes cannot be assigned by the aqFolderInfo.SetAttributes method:

Constant Value Description
faReparsePoint 1024 Reparse points are associated with files and folders via special tools and functions of the operating system.
faCompressed 2048 Compression of files and folders is enabled and disabled via specific tools and functions of the operating system.
faEncrypted 16384 Encryption of files and folders is enabled and disabled via specific tools and functions of the operating system.
faVirtual 65536 Virtual files and folders are created via special functions of the operating system.

Example

The following example makes the folder hidden:

JavaScript, JScript

function FolderInfoTest()
{
  var folder = aqFileSystem.GetFolderInfo("D:\\WorkingFolder");
  folder.SetAttributes(aqFileSystem.faHidden);
}

Python

def FolderInfoTest():
  folder = aqFileSystem.GetFolderInfo("D:\\WorkingFolder")
  folder.SetAttributes(aqFileSystem.faHidden)

VBScript

Sub FolderInfoTest
  Dim folder
  Set folder = aqFileSystem.GetFolderInfo("D:\WorkingFolder")
  folder.SetAttributes(aqFileSystem.faHidden)
End Sub

DelphiScript

procedure FolderInfoTest();
var folder;
begin
  folder := aqFileSystem.GetFolderInfo('D:\WorkingFolder');
  folder.SetAttributes(aqFileSystem.faHidden);
end;

C++Script, C#Script

function FolderInfoTest()
{
  var folder = aqFileSystem["GetFolderInfo"]("D:\\WorkingFolder");
  folder["SetAttributes"](aqFileSystem["faHidden"]);
}

The following example checks the folder’s attributes and makes the folder read-only and system.

JavaScript, JScript

function FolderInfoTest()
{
  var folder, attr, faReadOnlySystem;
  folder = aqFileSystem.GetFolderInfo("D:\\WorkingFolder");
  attr = folder.Attributes;
  faReadOnlySystem = aqFileSystem.faReadOnly | aqFileSystem.faSystem;

  if ((attr & faReadOnlySystem) == faReadOnlySystem)
    Log.Message("The folder is already read-only and system.");
  else
    {
    folder.SetAttributes(faReadOnlySystem);
    Log.Message("The folder is read-only and system.");
    }

}

Python

def FolderInfoTest1():
  folder = aqFileSystem.GetFolderInfo("D:\\WorkingFolder")
  attr = folder.Attributes
  faReadOnlySystem = aqFileSystem.faReadOnly | aqFileSystem.faSystem
  if (attr & faReadOnlySystem) == faReadOnlySystem:
    Log.Message("The folder is already read-only and system.")
  else :
    folder.SetAttributes(faReadOnlySystem)
    Log.Message("The folder is read-only and system.")

VBScript

Sub FolderInfoTest
  Dim folder, attr, faReadOnlySystem
  Set folder = aqFileSystem.GetFolderInfo("D:\WorkingFolder")
  attr = folder.Attributes
  faReadOnlySystem = aqFileSystem.faReadOnly Or aqFileSystem.faSystem
  If (attr And faReadOnlySystem) = faReadOnlySystem Then
    Log.Message("The folder is already read-only and system.")
  Else
    folder.SetAttributes(faReadOnlySystem)
    Log.Message("The folder is read-only and system.")
  End If
End Sub

DelphiScript

procedure FolderInfoTest();
var folder, attr, faReadOnlySystem;
begin
  folder := aqFileSystem.GetFolderInfo('D:\WorkingFolder');
  attr := folder.Attributes;
  faReadOnlySystem := aqFileSystem.faReadOnly or aqFileSystem.faSystem;
  if (attr and faReadOnlySystem) = faReadOnlySystem then
    Log.Message('The folder is already read-only and system.')
  else
    begin
    folder.SetAttributes(faReadOnlySystem);
    Log.Message('The folder is read-only and system.');
    end;

end;

C++Script, C#Script

function FolderInfoTest()
{
  var folder, attr, faReadOnlySystem;
  folder = aqFileSystem["GetFolderInfo"]("D:\\WorkingFolder");
  attr = folder["Attributes"];
  faReadOnlySystem = aqFileSystem["faReadOnly"] | aqFileSystem["faSystem"];

  if ((attr & faReadOnlySystem) == faReadOnlySystem)
    Log["Message"]("The folder is already read-only and system.");
  else
    {
    folder["SetAttributes"](faReadOnlySystem);
    Log["Message"]("The folder is read-only and system.");
    }

}

See Also

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

Highlight search results