Invoke Method (Rename) renames only filename1 when two filenames are similar

Hi All,

I used the Invoke Method to rename files successfully
Filename 1 is: Letter_A8010123Z_22102022.pdf, Bot renames it to: Letter_AXXXX123Z_22102022.pdf

Problem I faced:
Now, i have 2 similar files (not exactly the same filename) and the Bot renames only the filename 1 but throws this error (did not rename filename 2)
Filename 1 is: Letter_A8010123Z_22102022.pdf
Filename 2 is: Letter_A8014567Y_22102022.pdf

Error is:
Invoke Method: Could not complete operation since a file exists in this path 'C:\XXX\Letter_S801XXXXZ.pdf

This error popped up after it completed renaming the Filename 1 and couldn’t rename Filename 2

HI @ayeo22

Can you share the error screenshot

Hi @ayeo22 ,

Are you maybe trying to use the same name to rename both the files ?

don’t know how to attach the pic, here’s the link:

What I rename is actually replacing the characters 8010 with XXXX using Remove and Insert
Filename 1 renamed perfectly to: Letter_AXXXX123Z_22102022.pdf but Bot then stops when it comes to filename 2

Hope this clarifies

The error it self says like, You have two files in the sample folder @ayeo22

Try Like this expression

It will add _1 [Increment] after the each file.



@ayeo22 ,

Could you also let us know what are the parameters passed to the Invoke Method ?

sorry Gokul, adding a underscore followed by a number is not suitable for me.
Any other workaround?

Tell us what you need @ayeo22

If the file already exist the folder how do you need to handle it?

So i have mentioned like Put _Count Or you can tell us what you needed

First argument:

Second argument:

What I need is:
Filename 1 is: Letter_AXXXX123Z_22102022.pdf
Filename 2 is: Letter_AXXXX567Y_22102022.pdf

These 2 letters will be sent out to 2 different persons

@ayeo22 ,

Using this Expression in the second iteration, you might be picking up the renamed file again.

You Should Store the file paths or the excel and pdf file path collection in two different collection variables (Array/ List of String), then use the collection variables instead of Directory.GetFiles("")

pdfFilePaths = Directory.GetFiles("C:\XXX","*.pdf").ToArray

excelFilePaths = Directory.GetFiles("C:\XXX","*.xlsx").ToArray

Your Parameters in Invoke Method would then be :
First argument:


Second argument:


I am a newbie to UiPath

My mistake (the xlsx should be pdf, I only have all pdf files to rename.
Can you show me how to do that?

HI @ayeo22

Try Like this



here’s the result: all filenames now end with “.pdf.pdf”

Hi @ayeo22

You can Remove the .pdf from the Parameter in the Rename activity

  1. Use Assign activity
ArrString | Variable Type -> Array(String) = Directory.GetFiles(Environment.CurrentDirectory+"\Input1\","*.pdf")

  1. Use For each activity


  1. Use Rename activity


Gokul, thanks for your effort. Appreciated.

I tried SupermanPunch’s recommended solution and it works better for me.

1 Like

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