I have a Datatable with value and its key as header, how to replace the file name E.g. 1. File A1
to 1. File John, assuming in the datatable the first column of key is A1 and second column is value of John.
I think the fastest way is by saving the file name in the datatable as a Dictionary with key-value pairs; the key is the first column, the value is in the second column.
then to rename the file, say File1 named “A1” just use Rename File with the input : Config(“A1”).toString → you don’t have to hardcode the A1, but you could just input a string variable containing the File Name you wanted to rename, just make sure in your datatable includes the key for that File name.
You can replace the file name in a DataTable by following these steps:
- Use a “For Each Row” activity to iterate through the Data Table.
- Inside the loop, use an “Assign” activity to update the value of the “File A1” key with the new value “File John.”
For Each Row (row) in DataTable
Assign: row("A1") = "John"
End For Each
A docx has a name of 1. File A1, i want to change A1 to John using a datatable with column Key and Value, do you have sample file i can see?
but im changing a docx name, u got file example?
but i dont want hardcode it, i want which ever Key is on the file name i want to change it to its respective value of the docx name
yes, you could do that with Config(OldFileName).toString
OldFileName is a string variable of your old file name. Make sure that OldFileName is one of the Key (first column) in your datatable
what do you mean by key value pair, also how can i use this to change the docx file name to its value?
If the doc file is containing A1 we will search for the key A1 in Dictionary and the corresponding value will be replaced in the place of A1
Hi @Helpmepls
InputFile=File A1
You can use For Each Loop, In the loop store the value for key and value into the Variable For eg. KeyAndValue=CurrentRow("Key).ToString+CurrentRow(“Value”).ToString.
And After the Use Assign Activity
InputFile=InputFile.Replace(“A1”, KeyAndValue)
If your A1 is incrementing Create a Int32 variable and use it as a counter
Hopes this helps you
could you perhaps create in UiPath and send the file here as im still quite new to this and need a more visual guide thank you.
I forgot to mention the key could have brackets, let me send you example so you could use it to change
1.File- A2.docx (15.4 KB)
MASTER FILE.xlsx (19.5 KB)
1.File- A1.docx (15.3 KB)
these are the exact file, how could automate it instead of hardcode rename it
the file which i sent the key may not be exact to the file name part but both the key and parts of the file name has similar name which is A2
any updates? thank you
Working on it , Give me Few mins