Capture filename with incremental counter

Hi friends!

I’ve run into a little problem where I’m stuck; I expose it to you to see if it would be possible with this approach or should I see other options:
Suppose I receive many emails with attached pdf files, some of which can be called the same way, so when downloading those with identical names can be overwritten, so I have chosen to rename them when downloading adding an incremental counter and the result would be xxx_blablabla_001.pdf;yyy_blablabla_002.pdf;xxx_blablabla_003.pdf,etc…

The problem comes when trying to capture their corresponding names again to attach them to an email and send them from me. I have tried to capture its absolute path+name but I can’t. In addition, you would need to remove the counter again to send the attachments with their original name, that is, xxx_blablabla.pdf;yyy_blablabla.pdf,…

I understand that it is not possible to use the * as a wild card, just as we can use it with selectors or… if that would be possible?

Thanks in advance and I hope I have expressed myself understandably!

Welcome to the UiPath Community @mbercianop!

Try adding a suffix to each file name with “Ref” and the date time string to keep it unique.

Try this:
“xxxxx_Ref” +System.DateTime.Now.Tostring(“ssffff”)+”.pdf”

Then when you need to remove it. Try using this Regex pattern to remove the suffix when reattaching.

Hopefully this helps you :slight_smile:

Hi @mbercianop,

Welcome to the community.

You can store the names of the files in two lists. first before rename second post rename and then you can compare and exclude the extra characters which can give you the names. Also you can use substring to remove the counter added by you.


thank you very much @Steven_McKeering, @Shikhar_Tandon!
I will try the solutions that you offer me; I gave it some thought, but I don’t have much experience with Regex patterns yet, so I discarded it. I also thought of somehow trimming the string and to that end I set my counter to 001,002,…

both solutions are very logical and valid, so I would like to indicate both as correct. it’s possible?

No my friend you can only mark anyone thats Ok, please mark any one as solution so that the thread can be closed :slight_smile:


1 Like

Hey @mbercianop

You need to ‘Mark as solution’ for whichever one you use.

It’s important to mark a solution/close a post because others who have the same problem find the post, are more likely to click on it and therefore find the solution without having to scroll through all the responses :blush:

I’ll add a bit more information to my answer to see if that helps you :slight_smile:

Before reattaching the file (let us know if you need instructions there) you need to generate a new string variable without the “_Ref” part.
To do this can use an “assign” activity like this:
Assign Left:

Assign Right:
System.Text.RegularExpressions.Regex.Replace(INSERTCURRENTFILENAMEVARIABLE, “_Ref\d{6}”,"")

This will replace the highlighted with nothing (“”)

To then apply/update the new file name use a “move file” activity (Tip: you can even use the same folder - it doesn’t have to be a new folder). Then insert into the properties panel fields “existing Directory+Existing_filename” → “New_Directory+Str_NewFilename”.

Hopefully this helps :blush:

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