Posted Mon, 01 Apr 2019 13:53:29 GMT by

I have a process that uses a text file.

The Automate process start another external process that opens a text file and consumes it.

I assume it places a lock on the text file during this time.

Is there a way to determine if there is a lock on a file before Automate attempts to delete it?

Posted Tue, 02 Apr 2019 00:10:01 GMT by


There is an IF statement or Wait action to check if the file is in use.  From what I've seen though, text files are never locked.

<AMIF ACTIVITY="file_exist" FILE="C:\Users\dcannon\Desktop\11.txt" MODE="accessible" />
<AMWAIT ACTIVITY="file" FILE="C:\Users\dcannon\Desktop\11.txt" />
Posted Tue, 02 Apr 2019 05:48:40 GMT by

I get an "unknown step or invalid AML" for the second line

For the third line it converts to "Wait for file(s) <file name> to exist " when converting it to VISUAL

What will this do? The file does exist but in use my some other process

Using Version 10



Posted Tue, 02 Apr 2019 05:52:49 GMT by


The Wait step has a checkbox for "Wait until file is not in use", so the step will wait until it's free.  The steps I sent are for version 11.  Here are the v10 steps:

<AMIF ACTIVITY="file_exist" FILE="C:\Users\dcannon\Desktop\10.txt" MODE="accessible">
<AMWAIT ACTIVITY="file" FILE="C:\Users\dcannon\Desktop\10.txt" />
Posted Tue, 02 Apr 2019 06:30:24 GMT by

That doesn't appear to work,

Is used Powershell to lock my text file before running test code

This is my code: -

<AMIF ACTIVITY="file_exist" FILE="%elockbox &amp; &quot;\test.txt&quot;%" MODE="accessible">
<AMWAIT ACTIVITY="file" FILE="%elockbox &amp; &quot;\test.txt&quot;%" />
<AMFILESYSTEM ACTIVITY="delete" AM_RETRY="120" AM_RETRYDELAY="10000" SOURCE="%elockbox &amp; &quot;\test.txt&quot;%" />

The code does not wait at the first 3 line above at any stage and I end up with : -

Main](Step 5) File System failed (Error : The process cannot access the file '<directory>\test.txt' because it is being used by another process.)

at the last step


Posted Tue, 02 Apr 2019 06:35:27 GMT by

Powershell code to lock the file


$path = "C:\file.txt"
$mode = "Open"
$access = "Read"
$share = "None"
$file = [System.IO.File]::Open($path, $mode, $access, $share)
#Run below to release file lock
Posted Tue, 02 Apr 2019 06:59:18 GMT by


You would have to add additional logic to the IF statement.  As it is now, it will complete the IF statement instantly whether the statement is true or false.  It does look there was an issue with the Wait step waiting for the file to be accessible in version 10.  This appears to be fixed in version 11.

Here's an idea of what to add:

<AMPOWERSHELL>$path = "C:\Users\dcannon\Desktop\10.txt"
$mode = "Open"
$access = "Read"
$share = "None"
$file = [System.IO.File]::Open($path, $mode, $access, $share)</AMPOWERSHELL>
<AMIF ACTIVITY="file_exist" FILE="C:\Users\dcannon\Desktop\10.txt" MODE="accessible">
<AMSHOWDIALOG MESSAGE="not accessible" />
<AMPOWERSHELL>#Run below to release file lock
Posted Tue, 02 Apr 2019 07:21:04 GMT by

Thanks for your help.

Greatly appreciated.

I have something now.

<AMIF ACTIVITY="file_exist" FILE="%elockbox &amp; &quot;\test.txt&quot;%" MODE="not_accessible">



Posted Wed, 07 Aug 2019 02:34:59 GMT by


Is there a way to determine what user has a file locked?


Rich Flowers

You must be signed in to post in this forum.