Question

Cannot delete the last file in a folder in a loop action

  • 1 February 2023
  • 8 replies
  • 123 views

Badge +1

Good Afternoon - 

I am having an issue where i have a loop, wherein I do some processing to a series of pdfs. After Im done processing, I move the files to an archive folder, and delete from that current folder. This works, except for the last pdf file in the queue. When the bot encounters the delete task for the last file, I receive an error stating: “Unable to delete the file(s) ‘**file location omitted for post**’ because they are being used by another process. Try after sometime.

I have tried entering a delay, but to no avail. Every other file is deleted successfully.

Any ideas?


8 replies

Userlevel 5
Badge +14

@Rob 7023 within the loop after processing try to kill pdf service so that no threads will available… 

Badge +1

Im sorry, how do i do that?

 

Badge +1

Actually, when running in debug, i dont even see the pdf service running at all. 

I think the bot itself is somehow keeping it open. 

 

Userlevel 5
Badge +9

@Rob 7023 

Could you post a screenshot of your loop action?

REgards

Userlevel 7
Badge +13

Hi @Rob 7023 ,

 

Is this specific to a particular file?
If that’s the case, have you tried to delete it manually from that folder? If not, please check once and confirm.

Badge +1

This is not relative to a specific file, it is any time we loop through an entire folder of pdf files. 

Badge +1

Here is a screenshot of the loop: 

the loop initiation:

 

I deleted the file deletion

Userlevel 7
Badge +13

This is not relative to a specific file, it is any time we loop through an entire folder of pdf files. 

 

Test it with a separate BOT after keeping the last file in the Folder and try to delete that. See whether you are facing the same issue there or not.

 

 

Else, if it is really bothering you then, you can follow the below workaround. 

Use Try-Catch package and put the Delete action in Try and put the Continue in Catch. This will help you if the Delete action failed and the bot will continue the loop.

 

But you may need to delete the file manually once the BOT execution is over.

Reply