How to read multiple text file with different name in folder after loop?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
29-04-21 06:30 PM
Hi,
I am having 2 text file with different name in folder , the both text file is having more than 100 number of rows , In that I need to check the last row contains status =-10 or status>=0 For example text file sample I have mentioned below.
apr1,loop status>=0-------------------
apr2,loop status=-10-----------------
apr5,loop status=-10----------------
apr7,loop status>=0-------------------
apr8,loop status=-10-----------
In this sample text, multiple rows contains status =-10 , how to check the last row contains status=-10 or status >=0.
Can anyone guide me please, and also For the script , I have tried GET FILES action and store output as collection this fine , Then after loop I have tried READ ALL TEXT FROM FILES but I am not sure, In the input file name field how to give the filename because 2 text files having different name in that folder Kindly clarify this also.
Thanks in Advance
------------------------------
Jamuna T
RPA developer
Changepond Technology
chennai
------------------------------
I am having 2 text file with different name in folder , the both text file is having more than 100 number of rows , In that I need to check the last row contains status =-10 or status>=0 For example text file sample I have mentioned below.
apr1,loop status>=0-------------------
apr2,loop status=-10-----------------
apr5,loop status=-10----------------
apr7,loop status>=0-------------------
apr8,loop status=-10-----------
In this sample text, multiple rows contains status =-10 , how to check the last row contains status=-10 or status >=0.
Can anyone guide me please, and also For the script , I have tried GET FILES action and store output as collection this fine , Then after loop I have tried READ ALL TEXT FROM FILES but I am not sure, In the input file name field how to give the filename because 2 text files having different name in that folder Kindly clarify this also.
Thanks in Advance
------------------------------
Jamuna T
RPA developer
Changepond Technology
chennai
------------------------------
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
30-04-21 02:43 AM
Hi Jamuna,
You need to create two loops here.
1st loop is to get all the files in that folder, which you've already done so that's good.
Nested within this parent loop, you now need a child loop which access the first file in that folder and once you have all the text in a data item after using of Read all Text, you can use the Blue Prism object action Utility String Split Lines, which will get all the rows from your text in a collection.

Now you can get the no. of rows in this collection and easily access the contents of the last row based on that number.
Hope this helps.
------------------------------
Harpreet Kaur Product Consultant
------------------------------
You need to create two loops here.
1st loop is to get all the files in that folder, which you've already done so that's good.
Nested within this parent loop, you now need a child loop which access the first file in that folder and once you have all the text in a data item after using of Read all Text, you can use the Blue Prism object action Utility String Split Lines, which will get all the rows from your text in a collection.
Now you can get the no. of rows in this collection and easily access the contents of the last row based on that number.
Hope this helps.
------------------------------
Harpreet Kaur Product Consultant
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
30-04-21 07:16 AM
Hello!!
This is really easy with a simple piece of code, just follow this steps:
In the Object Properties, add:
Create a new page, and add a "code stage"
Define the Inputs / outputs:
Need to paste your path on the "Path" input variable.
The code looks like that:
You don't need to use a second loop to get the last line. Is better to use "File.ReadAllLines" and then get the last from the array list.
Hope this helps you
Bye 🙂
------------------------------
Pablo Sarabia
Programmer
Altamira AM
------------------------------
This is really easy with a simple piece of code, just follow this steps:
In the Object Properties, add:
External References: System.IO.dll
Namespace Imports: System.IO
Create a new page, and add a "code stage"
Define the Inputs / outputs:
inputs: variable "Path" as a Text
outputs: variable "dtResult" as a Collection
Need to paste your path on the "Path" input variable.
The code looks like that:
DataTable dt = new DataTable();
dt.Columns.Add("fileName", typeof(String));
dt.Columns.Add("lastLine", typeof(String));
DataRow row;
String[] arLines;
foreach(String file in Directory.GetFiles(Path))
{
row = dt.NewRow();
arLines = File.ReadAllLines(file);
row[0] = file;
row[1] = arLines[arLines.Length-1];
dt.Rows.Add(row);
}
dtResult = dt;
You don't need to use a second loop to get the last line. Is better to use "File.ReadAllLines" and then get the last from the array list.
Hope this helps you
Bye 🙂
------------------------------
Pablo Sarabia
Programmer
Altamira AM
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
30-04-21 12:00 PM
Hi Harpreet Kaur ,
Thanks for your response , Could you please mention how to give the logic in decision like last Row contains status =-10 or Status >=0. after used Split lines.
------------------------------
Jamuna T
RPA developer
Changepond Technology
chennai
------------------------------
Thanks for your response , Could you please mention how to give the logic in decision like last Row contains status =-10 or Status >=0. after used Split lines.
------------------------------
Jamuna T
RPA developer
Changepond Technology
chennai
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
30-04-21 03:31 PM
Hi Pablo Sarabia,
Thanks for your response, I will try this too, could you please guide me how to get the last from the array list.
------------------------------
Jamuna T
RPA developer
Changepond Technology
chennai
------------------------------
Thanks for your response, I will try this too, could you please guide me how to get the last from the array list.
------------------------------
Jamuna T
RPA developer
Changepond Technology
chennai
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
30-04-21 03:51 PM
Hello Jamuna!
The "array string" have the ".Length" property. This tells you how many lines do you have.
Use this:
String[] arLines = File.ReadAllLines(file); //Load the array
String lastLine = arLines[arLines.Length-1]; //Get the last line
Need to use "arLines.Length-1" cause the index start in 0 not, in 1.
Hope this helps you
Bye 🙂
------------------------------
Pablo Sarabia
Programmer
Altamira AM
------------------------------
The "array string" have the ".Length" property. This tells you how many lines do you have.
Use this:
String[] arLines = File.ReadAllLines(file); //Load the array
String lastLine = arLines[arLines.Length-1]; //Get the last line
Need to use "arLines.Length-1" cause the index start in 0 not, in 1.
Hope this helps you
Bye 🙂
------------------------------
Pablo Sarabia
Programmer
Altamira AM
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
30-04-21 04:07 PM
Thanks Pablo Sarabia , I will try as per this.
------------------------------
Jamuna T
RPA developer
Changepond Technology
chennai
------------------------------
------------------------------
Jamuna T
RPA developer
Changepond Technology
chennai
------------------------------
