ayeo22
(ayeo22)
October 22, 2022, 11:48am
1
Hi All,
I used the Invoke Method to rename files successfully
Example:
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)
Example:
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
Gokul001
(Gokul Balaji)
October 22, 2022, 11:49am
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 ?
ayeo22
(ayeo22)
October 22, 2022, 11:58am
4
don’t know how to attach the pic, here’s the link:
ayeo22
(ayeo22)
October 22, 2022, 12:02pm
5
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
Gokul001
(Gokul Balaji)
October 22, 2022, 12:04pm
6
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.
Path.GetFileNameWithoutExtension(Directory.GetFiles(Environment.CurrentDirectory+"\Input\","*.xlsx")(CInt(currentItem))).Remove(4,4).Insert(4,"XXXX")+"_"+currentItem.ToString
Regards
Gokul
@ayeo22 ,
Could you also let us know what are the parameters passed to the Invoke Method
?
ayeo22
(ayeo22)
October 22, 2022, 12:09pm
8
sorry Gokul, adding a underscore followed by a number is not suitable for me.
Any other workaround?
Gokul001
(Gokul Balaji)
October 22, 2022, 12:11pm
9
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
ayeo22
(ayeo22)
October 22, 2022, 12:11pm
10
First argument:
Directory.GetFiles(“C:\XXX,”*.pdf")(CInt(currentItem))
Second argument:
Path.GetFileNameWithoutExtension(Directory.GetFiles(“C:\XXX”,“*.xlsx”)(CInt(currentItem))).Remove(4,4).Insert(4,“XXXX”)
ayeo22
(ayeo22)
October 22, 2022, 12:12pm
11
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 ,
ayeo22:
Path.GetFileNameWithoutExtension(Directory.GetFiles(“C:\XXX”,“*.xlsx”)(CInt(currentItem))).Remove(4,4).Insert(4,“XXXX”)
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:
pdfFilePaths(CInt(currentItem))
Second argument:
Path.GetFileNameWithoutExtension(excelFilePaths(CInt(currentItem))).Remove(4,4).Insert(4,"XXXX")
2 Likes
ayeo22
(ayeo22)
October 22, 2022, 12:23pm
13
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?
Gokul001
(Gokul Balaji)
October 22, 2022, 12:25pm
14
HI @ayeo22
Try Like this
Environment.CurrentDirectory+"\Input1\"+Path.GetFileNameWithoutExtension(Directory.GetFiles(Environment.CurrentDirectory+"\Input1\","*.pdf")(CInt(currentItem))).Remove(4,4).Insert(4,"XXXX")+".pdf"
Regards
Gokul
ayeo22
(ayeo22)
October 22, 2022, 12:29pm
15
here’s the result: all filenames now end with “.pdf.pdf”
Gokul001
(Gokul Balaji)
October 22, 2022, 12:33pm
17
Hi @ayeo22
You can Remove the .pdf
from the Parameter in the Rename activity
Use Assign activity
ArrString | Variable Type -> Array(String) = Directory.GetFiles(Environment.CurrentDirectory+"\Input1\","*.pdf")
Use For each activity
Enumerable.Range(0,ArrString.Count)
Use Rename activity
Regards
Gokul
ayeo22
(ayeo22)
October 22, 2022, 12:45pm
18
Gokul, thanks for your effort. Appreciated.
I tried SupermanPunch’s recommended solution and it works better for me.
1 Like
system
(system)
Closed
October 25, 2022, 12:46pm
19
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.