What is the best way to delay an activity?

I have a flow which uses a MoveFile loop to move and rename many files on my hard drive.

The files are of different sizes, and, if a file is too large, the loop will through an error on the next iteration because the MoveFile activity is still processing the large file. Is there any way of implementing a “wait until activity is completed” instruction?

I’m hoping for something more efficient than just specifying an exact # of millisecond to delay the loop.


I been using a Retry Scope for this scenario with an “Is True” activity in the condition to check if the file was moved. The Retry Scope allows you to set the number of tries so it doesn’t get stuck in an infinite loop, and it’s dynamic since it moves on once the “Is True” condition is true.

1 Like

Thanks, sorry, Im a beginner with this software. From your solution, I think my loop should look something like the one below. However, what would be the exact way to implement this?

For Each item in Directory
Retry Scope (if Move File = False)
Move File

Did you find the “Is True” activity? It’s in the activity package, I think is called “Workflow Manager” or something similar.

Then you can do:

For Each oldfilepath in Directory
    Move File (oldfilepath to newfilepath)
    Retry Scope
        action section: empty
        condition section: Is True activity (File.Exists(newfilepath)

The retry scope would go after the move file, so it waits to move on after it.

You may select to use the Path Exists activity in the condition section, instead of using Is True with File.Exists()

You may also decide to use two conditions so you can check if the file was moved out of the first location and into the new location. For example, File.Exists(newfilepath) AndAlso Not File.Exists(oldfilepath)
Similarly, you can use two Path Exists activities to check these conditions in the action section. Then use the Output property on them to store the result to a boolean type variable, which you can use in the Is True activity in the condition section of the Retry scope.
For example:

For Each oldfilepath in Directory
    Move File (oldfilepath to newfilepath)
    Retry Scope
        action section:
            Path Exists (oldfilepath) //store boolean to oldfilepathExists
            Path Exists (newfilepath) //store boolean to newfilepathExists
        condition section: Is True activity (newfilepathExists AndAlso Not oldfilepathExists)

I hope that helps give you a few examples.

If you have any errors, feel free to post them and we can help resolve.


Thanks again for the help. So, now my loop looks like the one in this image:

When I run, this, I get an error stating that the Retry Scope didn’t execute as expected.

Maybe I have the Is True input/results set up incorrectly? (I’m not sure what the values should be there…)

How do you have the properties set for the Retry Scope? You should have a time of 00:00:01 with Retry Number at maybe 10 or 15

Hmmm, I tried that; and its still throwing the “Retry Didn’t Executed as Expected” error.

That error means that it used up all its retries, so it failed. Make sure you also rename the Retry Scope to say what it’s doing, so when an error occurs, you know that the file failed to move successfully.

I suggest, checking manually that the file successfully moved as intended. If it’s not, then you will get this error since it used up all its retries (assuming you have it set to retry long enough (10-15secs). If the file takes longer than that, then checking it manually while it’s running would confirm this.

If the file is being moved correctly and you still get the error, please show the code you have in the ‘Is True’ and that the file matches the new filename which you are moving the file to. (feel free to block out the username or any other info you’d like.


1 Like

Thanks for the help! Ultimately, I was able to solve this with a DO WHILE loop. Specifically:

Do While File.Exists (in original source folder) = TRUE

Since it was the File.Exists that was the key, I’m going to go ahead and mark this as the answer.


1 Like

Be careful with the Do While. If the file never exists, it gets stuck in an infinite loop, so you need some way to time it out like calculate the time before the loop and check the difference. This is normally why I suggest the Retry Scope because it’s essentially the same thing but exits after so many tries. There are scenarios, though, where the infinite loop will never be achieved, then the Do While is successful in that case. :+1:


Funny you should mention that…

For whatever reason, the DO WHILE loop worked perfectly three times in a row. Then, on the 4th and 5th times, I got stuck on an infinite loop.

Alright, I’ll play around with Retry Scope some more.

Sorry, i’m still not having any luck with this. I tried the FILE PATH approach you mentioned above but I keep getting a Move File error (process can’t access file because it is being used by another process).

This is the current workflow, I’m hoping maybe there’s an easy fix in here somewhere:


Your screenshot of your code looks correct. The “can’t access file” error usually means the file is opened somewhere. I would suggest confirming the file is not being used by anyone; also check the Task Manager to make sure it’s not opened in the background.

I couldn’t really get the Retry Scope solution to work for me, but, for what its worth, I think I did manage to narrow down the possible problems/solutions.

First Problem: If a file is too large, it won’t be downloaded by my script because downloading takes too long and the script starts downloading the next file before the larger file is completed.

Fix: I introduced a 3000ms DelayAfter on one of the automated click buttons which has resolved the issue for at least files up to 1300kb in size.

Second Problem: If the file is too large, the PDF move/rename operation will not work. I don’t know know if the problem is Adobe or Windows Explorer or what really.

Solution: While the operation wont work if I move/rename from PDF to PDF, it DOES work if I first move/rename from PDF to generic Windows “FILE” type. So, my solution is to convert/rename all PDFs into FILE and then save those in bulk as PDFs.

Seems to work for now; thanks for all of your help, its very much appreciated!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.