Renaming Files

So initially I create a datatable from a larger file, I really only need two values from the large excel file. Afterwards (tell me if I’m wrong here or if this is possible), what I think may work is that if I go through the directory to get files names I could put that into a datatable as well. Then if I combine those tables I have all the values I need in order to move my files.

So are you only using the two values to create the new filename, and the two values will be used in part of all of the new filenames?

Yes, basically the file names come in the like this: File_Part1, File_Part2…, I’m basically just trying to replace the file name with the Investor Name and another value from a data table.

Ok, one more question. Are these values in separate rows in the datatable, or separate columns?

My initial data table has 2 columns but we’re taking the values in the rows all the way down. The 2nd has one column and is just the names of the files within a specific folder

So is it that the first row of the workbook with 2 columns corresponds with the first row in the workbook with the filenames, the 2nd row of the 2 column workbook corresponds with the 2nd in the workbook of filenames, etc?

Yes sir that’s it

Ok, in that case, there is a way you can iterate over both. You can either combine the two datatables together by adding the column of filenames to the 2-column table, or you can iterate over the table of filenames, and use the Index from the For Each Row activity to access the same row in the table with the parts for renaming the file.

The first solution would take additional steps, but would condense the data. You would need to use Add Data Column to create the new column, and then use a For Each Row loop to add the data to the new column.

In the second solution, if Dt2 is the 2-column table, and RowIx is the row index variable, you can access the matching row with Dt2(RowIx). To get the value from column 1, you would use Dt2(RowIx)(0).ToString.