Moving Files in a For Each Loop using Try Catch Activity


#1

I have a For Each Loop that is converting .PDF’s to .TXT in a given folder. Some files will not be able to be converted causing an exception resulting in the loop to stop. I added a TRY/CATCH activity to move those files to a “ERROR” folder; however, the Move File activity in the Catch portion is returning another exception with the message " The process cannot access the file because it is being used by another process." Is there a way to move these files that are causing errors in order to keep the process running unattended? I attached a file of my process.

Main.xaml (11.5 KB)


#2

It seems to me that you are holding those files in memory whilst you are trying to convert them. The best thing to do would be to separate out your activities so you’re not trying to move them whilst they are still “in use”

Worst case you may need to actively drop them from memory using the Garbage Disposer but I wouldn’t have thought this would be necessary.

RD


#3

Thank you for the reply. I had an idea that that was the issue. How would i separate the activities in away that would still accomplish what i’m trying to do? In my opinion (as a new user), the activities seem to be as separated as they can be.


#4

Make a list or table of the items that fail. Then in a separate set of activities, maybe even a separate workflow, go and move the files/folders by looping through that list.


#5

Whenever I run an alternative process the process doesn’t loop after the catch portion has been ran. Is there a way to keep it looping even after an exception has been thrown?


#6

If the issue is with Adobe Reader being used, Try Kill Process Activity option before you move the file.


#7

Try moving the try/catch inside the for-each-file activity. Your current solution will stop after one conversion fails as it “jumps” to the catch block after an exception is thrown.


#8

There’s the problem. Thank you so much @Andreas


#9

Sorry I was reading on my phone and didn’t see the attachment :frowning:


#10

No worries, your input was greatly appreciated!


#11

Hi, Could you share the worked solution. Thanks for the query.