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:
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.
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.
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.
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.
initialize a datatable
read csv (into datatable)
merge to datatable from step 1 (Add keys if don’t exist)