Combine TXT Files

Today is literally my 2nd day using UIPath so please be patient and let me know how to correctly use the forum as needed.

I found an existing forum topic and the XAML example in the existing topic has an error and I’m getting the same error (Combine Text (.txt) files in UiPath)

I have a folder with 1,500 TXT files that I need to append together. I’ve already had success using the “Append To CSV” activity and basically I want to do the exact same thing except for 1,500 TXT files. I’m not finding an “Append To TXT” activity in UIPath so I think I need to use an “Assign” activity.

My XAML so far

  • create an arrayOfFileNames for all 1,500 TXT files (success)
  • process for each item in arrayOfFileNames and use “Write Line” activity to display each file name in Output so that I know I have that loop working (success)
  • then for each file I use “Read Text File” activity to assign contents of TXT file to a variable of type Sting and that var is called fileContentsFromSource
  • I created a var of type String (array of Strings) called targetTextArray
  • finally I do an “Assign” activity as follows targetTextArray = targetTextArray + fileContentsFromSource
    • reminder: targetTextArray is String and fileContentsFromSource is String
  • I get the following message: Compiler error(s) encountered processing expression "targetTextArray + fileContentsFromSource / Operator ‘+’ is not defined for types ‘1-dimensional array of String’ and ‘String’
  • So how do I combine together 1,500 TXT files?

Thanks!
Paul Ehrsam
My 2nd day using UIPath

Hi,

Perhaps you should use List<String> type instead of string array because number of array’s items is fixed. Hope the following helps you.

Main.xaml (6.0 KB)

Regards,

1 Like

Thanks Yoichi for leading me in the right direction. I used the List[String] variable type you suggested as follows:

  • Variable type >>> Browse For Types … >>> search for “list” >>> used mscorlib / system.collections.generic / List[T] >>> then selected “String” under systems.collections.generic.list >>> that got me the List[String]

Then I used the Add to Collection activity you suggested to load up my variable “targetListCollection” of type List with the contents of my 1,500 TXT files so that I have all my data now loaded up into my “targetListCollection” variable

Finally I looped through my “targetListCollection” variable and used the “Append Line” activity to write one row at a time to my targetFile.txt file that now contains all the data from 1,500 TXT files.

Less than two days using UIPath and I already like it way better than Excel/VBA which was my only other tool for doing this type of work!

1 Like

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