Move multiple files from multiple location to multiple location along with renaming

I had created an automation where I was moving multiple files from single folder to another folder along with renaming them.

Now, I wish to scale up the same automation where I want to move multiple files to multiple locations and rename them.

I am using a reference excel file to add input path and output path and rename suffix column. This is used by UiPath to determine which files is to be moved to which folder along with what naming convention.

The challenge I am facing is I am unable to loop it for multiple folders.

Can someone please help.

So I would assume each row in your excel is an input folder and output folder etc.

The trouble you are having is it’s not looping through each row in the Excel to use that data to move the files?

Hey,
Simply you can use Read range activity
Then use for each row activity

And then you can use move file activity and pass path in move file activity.

Thanks,

Yes right.

as @Rounak_Kumar1 suggested, you would need to use the For Each Row activity to loop through each row in the excel file and utilse the data in each column to complete your actions:

i.e.

For Each Row in Datatable
   Input = Row.Item("Input Path").ToString
   Output = Row.Item("Output Path").ToString
   Suffix = Row.Item("Rename Suffix").ToString

NewDestination = Output.Insert(Output.LastIndexOf("."c),Suffix)

Move File Activity - From (Input) To (NewDestination) 

I tried but it didn’t worked.

Currently, it’s only moving 1 file and renaming it and after that it says could not find the same file which it has just moved.

Snap of error message:

When you are moving the file, same exact file name should be there
you are keeping the file path in excel right
then you should keep move file it will move one by one just like it is reading row by row(File Path) with the help of For each row

Thanks

Can you advise what did I do wrong here.

Code in “From” of move file: CurrentFile.FullName

Code in “To” of move file: Destination.ByField(“Destinatination Path”)+system.Io.Path.GetFileNameWithoutExtension(CurrentFile.ToString)+Suffix.ByField(“Suffix”)+system.io.Path.getextension(CurrentFile.ToString)

Could you please send me the Input excel File?
it will help me to Short out
Thanks

You dont need so many for each row looped inside each other - just one For Each Row for the excel file for the whole sheet rather than specific columns

You then use the column names per row to do the move file.

For Each Excel Row (Set For Each to (CurrentRow) and In Range to ([Excel] Sheet1)
   Input = CurrentRow.Item("Input Path").ToString
   Output = CurrentRow.Item("Output Path").ToString
   Suffix = CurrentRow.Item("Rename Suffix").ToString

Yes it got resolved. I was using too many loops

1 Like

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