Forum Discussion
HKosova
Alumni
14 years agoHi Ofer,
When a file is being created, it is locked. In this case, file opening functions fail with an error. So, to wait until a file lock is released, you can call a file opening function in a loop until it succeeds.
Using TestComplete's built-in aqFile object, it should be similar to this:
When a file is being created, it is locked. In this case, file opening functions fail with an error. So, to wait until a file lock is released, you can call a file opening function in a loop until it succeeds.
Using TestComplete's built-in aqFile object, it should be similar to this:
function Test()
{
var ERR_UNABLE_TO_OPEN = -2147467259;
var locked;
// Start the asynchronous file copying
Sys.OleObject("WScript.Shell").Run("cmd /k copy E:\\VeryLargeFile.exe E:\\VeryLargeFile2.exe");
do
{
locked = false;
try {
aqFile.OpenBinaryFile("E:\\VeryLargeFile2.exe", aqFile.faRead, false).Close();
}
catch (err)
{
if (err.number == ERR_UNABLE_TO_OPEN)
{
locked = true;
aqUtils.Delay(1000);
}
}
}
while (locked);
}