Hi everyone,
I have a folder containing a number of text files that I want to read and iterate and capture matched specific data value using regular expressions. Each text file has its own set of data values to be captured.
I have tested the regular expressions at .NET Regex Tester - Regex Storm and am able to match the desired text value correctly. However, in the UiPath workflow sequence I am unable to get any match or output any of the desired data value from the text files. Below are the list of steps I took to building the workflow but I am not sure if I have missed out any steps or having any mistakes in the workflow activities.
Any assistance is greatly appreciated.
Here are the workflow sequence done so far:
-
I add a Assign activity to get the text files path location. Folder is a string variable of the full path where the text files are located.
filesArray=Directory.GetFiles(Folder) -
Next, I add a For Each activity to loop each item in filesArray. In the Body of the For Each activity, I add Read Text File activity with Filename=item.ToString (as the path of the file to be read). The Output variable is textInput of string variable type.
-
Next, I add a Assign activity to read the text file line by line with a System.String variable textStr=textInput.Split(Environment.NewLine.ToArray()).
-
Next, I add a Matches activity to configure the regular expressions. Input variable=textStr.ToString and Result=regexMatch of variable type System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>.
Here is the regex:
(?<=SERVER: )\w+|(?<=SCSI Disk Device: )…|(?<=Gb.Gb.+Gb\s+)\d+.:
Here is a sample text and the value highlighted in bold are the data to be captured as input into Excel file:
SERVER: server001
SCSI Disk Device: OK
SCSI Disk Device: OK
SCSI Disk Device: OK
SCSI Disk Device: OK
Drive Size Used Free Free(%)
C: 499Gb 131Gb 368Gb 73.7
D: 99Gb 10Gb 89Gb 89
E: 1843Gb 800Gb 1043Gb 56.5
F: 1843Gb 647Gb 1195Gb 64.8