Description
The Exists
property returns True if the file to which the given aqFileInfoObj
object corresponds is found. Otherwise, the property returns False.
Declaration
aqFileInfoObj.Exists
Read-Only Property | Boolean |
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
True if the file exists, and False otherwise.
Remarks
If you try to obtain the aqFileInfo
object for a file that does not exist, an error will occur.
Example
The code below checks file availability. If the file exists, the Hello, World! text line will be added to its contents. Otherwise, the script will throw an exception.
JavaScript
function aqFileInfoExample()
{
let sPath = "C:\\FileName.txt";
try
{
//Checks whether the desired file exists
if (aqFileSystem.GetFileInfo(sPath).Exists)
{
aqFileSystem.GetFileInfo(sPath).WriteToTextFile("Hello, World!!", aqFile.ctANSI);
}
}
catch(e)
{
// Posts an error message to the test log
Log.Error(e.message);
}
}
JScript
function aqFileInfoExample()
{
var sPath = "C:\\FileName.txt";
try
{
//Checks whether the desired file exists
if (aqFileSystem.GetFileInfo(sPath).Exists)
{
aqFileSystem.GetFileInfo(sPath).WriteToTextFile("Hello, World!!", aqFile.ctANSI);
}
}
catch(e)
{
// Posts an error message to the test log
Log.Error(e.description);
}
}
Python
def aqFileInfoExistsExample():
sPath = "C:\\MyFile.txt"
try:
FileInf = aqFileSystem.GetFileInfo(sPath)
# Performs actions over the file
# ...
# Checks whether the specified file has not been deleted or moved
if FileInf.Exists:
# Writes text to the file
FileInf.WriteToTextFile("Hello, world!", aqFile.ctANSI)
except Exception as e:
Log.Error("The file has been deleted or removed.")
VBScript
Sub aqFileInfoExample
Dim sPath, File
sPath = "C:\asdf\vvasdasd.txt"
Err.Clear
On Error Resume Next
' Checks whether the desired file exists
Set File = aqFileSystem.GetFileInfo(sPath)
If aqFileSystem.GetFileInfo(sPath).Exists Then
' Writes text to the file
Call aqFileSystem.GetFileInfo(sPath).WriteToTextFile("Hello, World!", aqFile.ctANSI)
End If
If Err.Number <> 0 Then
' Posts an error message to the test log
Log.Error Err.Description
End If
End Sub
DelphiScript
function aqFileInfoExample;
var sPath;
begin
sPath := 'C:\FileName.txt';
try
// Checks whether the desired file exists
if aqFileSystem.GetFileInfo(sPath).Exists then
// Writes text to the file
aqFileSystem.GetFileInfo(sPath).WriteToTextFile('Hello, World!', aqFile.ctANSI);
except
// Posts an error message to the test log
Log.Error(ExceptionMessage);
end;
end;
C++Script, C#Script
function aqFileInfoExample()
{
var sPath = "C:\\FileName.txt";
try
{
// Checks whether the desired file exists
if (aqFileSystem["GetFileInfo"](sPath)["Exists"])
{
// Writes text to the file
aqFileSystem["GetFileInfo"](sPath)["WriteToTextFile"]( "Hello, World!!", aqFile["ctANSI"] );
}
}
catch(e)
{
// Posts an error message to the test log
Log["Error"](e["description"]);
}
}
See Also
Working With Files From Scripts
GetFileInfo Method
Name Property
Path Property