Problem with combining several txt files

Hello. I have problem with combining txt files into one.
When trying to use Add data row activity to append 22 txt files , the following error appears:

image

I suppose the cause is number of rows because in some other similar situations process works well, but with less rows.
Is there a way to expand number of rows that could be read and merged into one file?

Hi @Olivera_Kalinic Do you need to combine 2 txt files with tabular data (for example csv)?

Or 2 files with free text?

Itā€™s not the number of rows. Itā€™s exactly what the error says, the array has a different number of items than the datatable has columns.

Do you need to have it output as a data table? If not, Iā€™d avoid that. You can append text files with the ā€˜Append Lineā€™ activity.

Or just loop through the files and append each one to the same variable, then write the whole variable to a text file.

2 Likes

image

image

image

image

1 Like

Thatā€™s cleaner than what I was thinking. I was thinking of appending to the file at the end of the loop for each file. What type is the variable ā€œdestinationDataā€? Just a string?

Yep, just a string. Text files are read into strings. By the way, note that my example assumes there are only the files you want to read, in that folder. Obviously you may need to adjust this logic to grab only the files you need.

You could use Append Line to append to the destination file each time, but I prefer to avoid unnecessary reads/writes. Concatenating everything into a variable and then writing it once is less resource intensive.

1 Like

That is exactly what I did before, but after thah I have few steps:

  • creating excel file from final csv
  • using filter to add rows from final excel file, that have to be deleted, into table tabelaZaBrisanje

During second step, error that I mentioned before, appears.

image

I note that the error does not occur if fewer files are usedā€¦

Why would you do this? If Excel is what you want, then just write to Excel - donā€™t write to CSV then convert.

Seems like your csv files are not consistent. Different structure/number of columns causing the errors. You can only Add Row using an array if your table structure remains consistent otherwise it will be buggy.

Also, you could use Filter Datatable activity instead of looping and using a condition to add to another table.

  1. initialize a datatable

  2. Loop
    read csv (into datatable)
    merge to datatable from step 1 (Add keys if donā€™t exist)
    Loop End

  3. Filter Datable