How can you read a notepad file line by line?

Hi there. I am working on a new automation process and need help. I would like to know how to read each line (/ row) in a notepad file and execute a command based on what the line says (with a sort of ‘anchor base’ function). After executing the line, to delete it and move to the next line and repeat the cycle. I am pretty new to UiPath and therefore require some assistance.

Thanks in advance.

Hi @VladP ,

Try the Below using Assign Activity :

File.ReadAllLines("YourTextFilePath")

This will output an Array of String value.

2 Likes

Hi Arpan,
Thanks for your response. Is using ‘Read Text File’ and saving the output as a variable an option too? How do I then split the text line by line?

Thanks

Don’t try to read line by line. Read the whole thing into a variable, split on VbCrLf, then loop through the resulting array.

1 Like

@VladP ,

You Could Check the Below Expression :

strArray = Split(strText,Environment.NewLine)

Where strText is the String Output from Read Text File Activity, strArray is an Array of String type variable.

You should be able to then loop through the strArray one by one using For Each Activity.

Let us know if this doesn’t work.

1 Like

Hi,

I did what you told me and it worked but when I use the ‘For Each’ activity it returns all the lines * the amount of lines there are in the file. How can I make it read each line individually and make it follow its command? Say f.e. BTCUSD BUY is a line, how can I make it carry out the command? Is an ‘Anchor base’ activity useful?

Thanks.

@VladP , Could you let us know what do you mean by this ? For Confirmation on the Split Method working properly, Could you maybe use a Write Line Activity and Check the Count of values present in strArray variable like below :
image

For Data that is in the form of Text/String, we use String Manipulation methods or Regex Methods to get the Desired result.

But what should your Command do with the line/each line ? What exactly is the Output Required?

The Split Method works now thanks.

My command should look through each line and navigate on E-Toro to the currency in the line and then execute a position based on BUY, SELL or CLOSE. So if it says BTCUSD BUY, I want it to look through my watchlist on E-Tor, find BTCUSD, and then click BUY on the currency.

Thank you.

@VladP , Maybe we would require more insight on the Data to understand better, Could you Provide your Text data present in some of the lines. So that we can visualize better and suggest you the appropriate solution.

Also, we do see there are steps which I assume involves UI Automation, Navigating to a Website on a Browser ? However we could keep this aside for now, and work on our String Manipulation/Check required.

orders.txt (130 Bytes)
So each line contains a market (f.e. BTC) and a position (f.e. BUY). I want to read each line in the file and carry out the command.

@VladP ,
Could you Check the Below workflow :
StringSplit_Check_Execute.zip (3.0 KB)

The market and command variables contain the first word and second word of each line respectively on each iteration.

I believe using these variables you could make the decision of BUY, SELL or CLOSE.

We may require to use a Switch Activity, which I have also included with just the Skeleton as we do not know the UI information for further Steps/activities.

The Output Currently is Logged as below :
image

1 Like

You are a life saver Arpan! Thanks for your service. I now also better understand how the split method works when using the ‘For Each’ activity.

Thanks a lot!

1 Like

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