Move File Error when using Load Image

Hi UiPath experts,

I want your help.

I’m using Load Image Activity and then OCR to extract the specific text from the image and then i have to move the image file to another folder. For that I’m using the “Move File” Activity. But I’m getting the below error:

Move File: The process cannot access the file because it is being used by another process.

Thanks,
T.Aditya

Hi @ADITYA_T ,

The error you’re encountering occurs because the image file is still being held by the Load Image or OCR activity when the Move File activity attempts to move it.

Add a Retry Scope Activity: This will allow you to repeatedly attempt the move operation until it succeeds.

The Retry Scope will attempt to move the file up to 3 times (default value), with a 1-second interval between attempts. You can adjust the NumberOfRetries and RetryInterval properties in the Properties Panel based on your success rate. If the file is still in use after all retries, you can log an error or take other actions as needed.

If the above solution doesnt work as expected then you can try using garbage collection (GC) to force the release of any resources that might still be holding onto the file.
Below is the Sample workflow Of your Scenario

Hope it helps you !

Regards,
Vikas M

Hi @Vikas_M

I tried both the methods but it still throws the same error.

@ADITYA_T,

Move the Load image and OCR activity to separate workflow and invoke it your current workflow. Pass the required output with Out Arguments from it. This way UiPath will do garbage collection properly without explicit GC calling.

Thanks,
Ashok :slight_smile:

Hi @ashokkarale

I’m already using the seperate workflows for OCRs and for Moving Files.

Thanks,
Aditya.

HI,

Can you try to use FileStream class as the following sample

fs = New FileStream("test.png",System.IO.FileMode.Open,System.IO.FileAccess.Read)
img = System.Drawing.Image.FromStream(fs)

// Do something

img.Dispose()
fs.Close()

Then, delete the file

Sample
Sample20240826-2.zip (5.2 KB)

Regards,