Read first line from text file and looping for next line


Is it possible to make the robot read the first line from a text file and write that only one line into another text file? Then, loop the process for second and third line in the same text file as the first one. Please, can anyone help?
This is the sample that I’m working on right now.Main.xaml (11.6 KB)

@Aoyama You can use below command

File.ReadAllLines("File path along with filename and extension") 

Above command gives array of string as in text file, each array element will contain line from text file.

Hi @Manjuts90,

Thanks for your reply. Actually, where do I need to use that command? Sorry because I’m still new to UiPath.

I’ve tried use the command in assign activity and assign it to one of my variable. When I run the robot, it only write “system.string”.

Hi @Aoyama,

The error is occurring because the data type of file should be IEnumerableof string.

Please find the code for your query and please change the value of file ‘Path’.
Main.xaml (6.5 KB)

@Aoyama U have to use assign activity and on left side u have to String array variable and on right side u have to use statement below.

1 Like

Hi @Suman7,

Thanks for the attachment file that you give. It work but not like what I want to do. Actually, I already wrote 3 lines of sentence in a text file. What I want to do is I want the robot to read only first line from those 3 lines and write that sentence in another text file. Then after a few minutes, the robot will continue read the second line from the same text file and do the same as the first one. Same goes for the third lines. Is it possible to make it work?

Thanks @Manjuts90 for your instruction.

1 Like

@vvaidya - Can you please help us on this query.

Did you got the solution of your query? please share as I am also having the same problem.

Hi @servesh20,
Please find the below sample of workflow that I have used for solving this problem. Hope it will help you. Thank you.
Main.xaml (6.7 KB) Test.txt (83 Bytes)


Thanks bro its working fine…
Also for any specific data from datatable use x = row.contains(“xyz text”) in If condition.

No problem and thanks for the sharing. :smile:

1 Like

Hi @Aoyama
Thanks for the work around.

1 Like