aqFileSystem.ChangeAttributes Method

Applies to TestComplete 14.91, last modified on July 20, 2021

Description

Use the ChangeAttributes method to set, clear or invert the file system attributes of a file or folder. To check whether a file or folder has certain attribute(s), use the aqFileSystem.CheckAttributes method.

Declaration

aqFileSystem.ChangeAttributes(PathAttributeAction)

Path [in]    Required    String    
Attribute [in]    Required    Integer    
Action [in]    Required    Integer    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Path

Defines the fully qualified path to the file or folder whose attributes should be modified.

Attribute

An integer number 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 or folder.
faHidden 2 A hidden file or folder.
faSystem 4 A system file or folder.
faArchive 32 An archive file or folder.
faNormal 128 A file or folder 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.

Action

Specifies the action that the method should perform. This parameter can be one of the following constants defined in the aqFileSystem object:

Constant Value Description
fattrSet 0 Sets the corresponding attribute(s).
fattrInvert 1 Toggles the current state of the attribute(s).
fattrFree 2 Clears the corresponding attribute(s).

Result Value

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

Remarks

The following attributes cannot be altered by the ChangeAttributes 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 code snippet demonstrates how you can make a file read-only during the test run:

JavaScript, JScript

aqFileSystem.ChangeAttributes("C:\\MyFile.txt", aqFileSystem.faReadOnly, aqFileSystem.fattrSet);

Python

aqFileSystem.ChangeAttributes("C:\\MyFile.txt", aqFileSystem.faReadOnly, aqFileSystem.fattrSet)

VBScript

Call aqFileSystem.ChangeAttributes("C:\MyFile.txt", aqFileSystem.faReadOnly, aqFileSystem.fattrSet)

DelphiScript

aqFileSystem.ChangeAttributes('C:\MyFile.txt', aqFileSystem.faReadOnly, aqFileSystem.fattrSet);

C++Script, C#Script

aqFileSystem["ChangeAttributes"]("C:\\MyFile.txt", aqFileSystem["faReadOnly"], aqFileSystem["fattrSet"]);

The code below clears a folder’s read-only and hidden attributes:

JavaScript, JScript

aqFileSystem.ChangeAttributes("C:\\MyFolder", aqFileSystem.faReadOnly | aqFileSystem.faHidden, aqFileSystem.fattrFree);

Python

aqFileSystem.ChangeAttributes("C:\\MyFolder", aqFileSystem.faReadOnly | aqFileSystem.faHidden, aqFileSystem.fattrFree)

VBScript

Call aqFileSystem.ChangeAttributes("C:\MyFolder", aqFileSystem.faReadOnly Or aqFileSystem.faHidden, aqFileSystem.fattrFree)

DelphiScript

aqFileSystem.ChangeAttributes('C:\MyFolder', aqFileSystem.faReadOnly or aqFileSystem.faHidden, aqFileSystem.fattrFree);

C++Script, C#Script

aqFileSystem["ChangeAttributes"]("C:\\MyFolder", aqFileSystem["faReadOnly"] | aqFileSystem["faHidden"], aqFileSystem["fattrFree"]);

See Also

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

Highlight search results