Renaming Files from CSV file

I have 500 files I need to rename. currently the files are named by Client ID.SubID but I need them to be named by company names.

I have a CSV file that has the ClientID.SubID (ie., Company.001) and list the company name next to it (ABC Company). I have 500 files in explorer that I want to check against the csv file, find the correct client Id and rename the file with the corresponding file name. Can this be done in uipath? if so HOW?

I have tried the Move file activity but I am not sure on how to get my output name from the Csv file to be copied and then pasted as the new file name. i have seen a lot of post on how to rename and trim or manipulate a current file name but how can I cut and paste a name from a n excel spreadsheet or scraped date to make it the new file name?

Please anyone HELP

Hi @Donna_Roberts, :slight_smile:

I suggest you to join our Uipath Academy and take the Foundation Course to understand Uipath’s World. It’s free and you also can obtain a Certificate :open_mouth:

But, anyway jeje let me try to guide you in order to build your solution.

Read Range: Use to read the Excel file and store all the data from your CSV that has ClientID.SubID on a DataTable variable.

activities.uipath.com

Read Range

UiPath.Excel.Activities.ExcelReadRange Reads the value of an Excel range and stores it in a DataTable variable. If the range isn’t specified, the whole spreadsheet is read. If the range is specified as a cell, the whole spreadsheet starting from…

For Each Row: Use to iterate through all the rows from the DataTable generated in the read range activity in order to get ClientID.SubID by row

activities.uipath.com

For Each Row

UiPath.Core.Activities.ForEachRow Executes an action once for each row in the DataTable provided. # Properties ## Input * DataTable - The DataTable variable for which an action is to be executed once for each row. ## Misc * Private

Inside Loop , use assign acitivity to populate a variable with the name of ClientID.SubID extracted from Excel, after that,

Use Path.GetFileName(“string name from Row(“ClientID.SubID”)”) in your for each loop like this…

name

Well , this is the way you need to follow…

Hope it helps!:slight_smile:

Regards,
~Diego Turati

1 Like

Hi @Donna_Roberts

As @DiegoTurati mentioned, these stuff are quite easier if you try out the foundation training in the academy :slight_smile:

However I just thought of sharing a sample xaml file because I already have a similar one created for one of my own tasks. Just did some tweaks so that you can have a look on how it can be done easily. I have also added some comments in each activity so that you can understand the process easily.

Hope this helps…

RenamingFilesBasedOnExcel.xaml (10.0 KB)

Let know how it goes

If this works out for you, please make sure to mark my answer as the solution too…

1 Like

Thank you for the file it is very helpful… One question… I am getting errors at the Assign step…it says Cannot assign from type ‘System.String’ to type ‘System.String’ in Assign activity ‘Assign’.

What does this mean? I have started the Academy but in a bind and really trying to figure this out.

Hi @Donna_Roberts

The error says, it cannot assign a string to a string array. So why this error occur is because:
the command you have given under the value segment of the assign activity is surrounded by a double quotation. So though it has the command in it, it acts as a full string because of the double quotations :slight_smile:

So change it as below:
Directory.GetFiles("C:\Testing UIPATH\Centur Extensions\Released in ELF")

This will work for you :slight_smile:

Can you help me again with this solution you provided recently. I am working on the “If Condition” and have a quick question…

Path.GetFileNameWithoutExtension(item).ToString.Equals(row(“ClientID.SubID”).ToString)

Should (item) be something??? because I have an error I have attached the screenshot

could you take a screenshot of the foreach’s properties ?

After that, I saw the problem and eliminated all the errors