aqFile.SetFileAttributes Method

Applies to TestComplete 15.42, last modified on September 08, 2022

Description

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

Declaration

aqFile.SetFileAttributes(Path, fAttr)

Path [in]    Required    String    
fAttr [in]    Required    Integer    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Path

Specifies the fully-qualified path to the desired file.

fAttr

An integer value that specifies the file’s new attributes. This parameter can accept one 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 file.
faHidden 2 A hidden file.
faSystem 4 A system file.
faArchive 32 An archive file.
faNormal 128 A file that does not have any other attributes set.
faTemporary 256 A file that is used for temporary storage.
faOffline 4096 A file whose data is physically moved to offline storage.
faNotContentIndexed 8192 A file that is not to be indexed by the content indexing service.

Result Value

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

Remarks

The following attributes cannot be assigned by the aqFile.SetFileAttributes method:

Constant Value Reason
faDirectory 16 A file cannot be transformed to a folder and vice versa.
faSparseFile 512 Files are marked as sparse or not sparse via special tools and functions of the operating system.
faReparsePoint 1024 Reparse points are associated with files and folders via special tools and functions of the operating system.
faCompressed 2048 File and folder compression is enabled and disabled via specific tools and functions of the operating system.
faEncrypted 16384 Files and folder encryption is enabled and disabled via specific tools and functions of the operating system.
faVirtual 65536 Virtual files are created via special functions of the operating system.

Example

The following example demonstrates how you can make a file read-only and hidden (preserving other attributes):

JavaScript, JScript

function SetFileAttributesSample()
{
  var fileName = "C:\\MyFile.txt";
  var fa = aqFile.GetFileAttributes(fileName) | aqFileSystem.faReadOnly | aqFileSystem.faHidden;

  aqFile.SetFileAttributes(fileName, fa);
}

Python

def SetFileAttributesSample():
  fileName = "C:\\MyFiles\\MyFile.txt"
  fa = aqFile.GetFileAttributes(fileName) | aqFileSystem.faReadOnly | aqFileSystem.faHidden
  aqFile.SetFileAttributes(fileName, fa)

VBScript

Sub SetFileAttributesSample
  Dim fileName, fa

  fileName = "C:\\MyFile.txt"
  fa = aqFile.GetFileAttributes(fileName) Or aqFileSystem.faReadOnly Or aqFileSystem.faHidden

  aqFile.SetFileAttributes fileName, fa
End Sub

DelphiScript

procedure SetFileAttributesSample;
var fileName, fa;
begin
  fileName := 'C:\\MyFile.txt';
  fa := aqFile.GetFileAttributes(fileName) or aqFileSystem.faReadOnly or aqFileSystem.faHidden;

  aqFile.SetFileAttributes(fileName, fa);
end;

C++Script, C#Script

function SetFileAttributesSample()
{
  var fileName = "C:\\MyFile.txt";
  var fa = aqFile["GetFileAttributes"](fileName) | aqFileSystem["faReadOnly"] | aqFileSystem["faHidden"];

  aqFile["SetFileAttributes"](fileName, fa);
}

See Also

Working With Files From Scripts
GetFileAttributes Method
Attributes Property
Attributes Property
ChangeAttributes Method
CheckAttributes Method
SysErrorMessage Method

Highlight search results