TASK - Read all text file from folder in Loop, dynamically extract data from each file based on few keyword stored in Array and load in extracted value in Table/Excel

Hello
I am working on one task on Automation which are as below

  1. Read all text file from folder in Loop - completed
  2. dynamically extract data from each file based on few keyword stored in Array - Facing Challenges
  3. and load in extracted value in Table/Excel - am aware of this process

Currently facing challenges on Task 2
I have array of 5 element code “A123” “B234” “C345” “D567” “E098” .This would present anywhere in “Text file” which am reading in task 1.

Q1) looking for solution -Read all lines for text file in loop
With read text - i am able to get Text file content
But not able to read all lines - in loop till last line.
Here i need some direction on, how to use File.readalllines or any other method to read all lines of text files.
Next
Q2) and dynamically, how to scan each lines with each of Code of Array and once its found , with its start position will be getting next 15 length word after that which is my ultimate GOAL.

I would be able to last part of extract, once am able to solve able to problems
StartIndex = item.ToString.IndexOf(policyPrefix,0)+policyPrefix.Length
Output = = item.ToString.Substring(startIndex-4,14)

Hi,
regarding the first question, if your need is to read a file line by line, probably the best option would be to use the ReadLines method:
var fileLines = File.ReadLines(fileName);
foreach (var fileLine in fileLines) {
// do job here
}

Another way could be:
using (StreamReader streamReader = File.OpenText(fileName)) {
String fileLine = String.Empty;
while ((fileLine = streamReader.ReadLine()) != null) {
// do job here
}
}

In both cases, as you see, fileLine is the string you need to check in order to verify if it contains (if I understand correctly) one of your element code.

1 Like

Thanks Romerm …
StreamREedar with Regex combination worked. there was one other post in Uipath Forum.So with both your’s solution and along with regex worked for my problem.

I completed my task in time … Thanks to you and UiPAth Forum . it nice for Beginners like me

Hi Romerm

I am looking for one more dynamic solution for my problem detailed in below Post

Thanks in Advance …

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