Have you ever came up with a CSS, XML or HTML File that is full of empty unnecessary rows and can’t be bothered to spend the time needed clearing it up? Well you no longer need to!!! You can use WinAutomation to do the boring work for you!
To start with we need to read each Line of the File. We can do that using the “Read text from File” Action, and store the content into %FileContentsList%.
We make sure that we select the Store File Content as List option, so that we can then work on each Line individually.
We will then use the “For Each” Action to read each Line from our list %FileContentsList% variable.
For each Line we will trim the white space characters “from both the beginning and end” so that we are sure that we will not only delete the empty rows, but also all the rows that contain nothing more but spaces and tabs.
Using the “If” Action, we will get the %TrimmedCurrentLine% and check whether it contains any characters.
In order to achieve us checking for “no text” in our Line, we will use a simple evaluation %””%. As you can see there is no text between our quotes; that means that we are looking for any phrase that contains no characters.
Had we had the word ”Hello”, we would then be looking for the word Hello in our text. So anything in quotes within % symbols means that we are looking for text and not for a predefined variable.
If it is not empty, we will write the %CurrentLine% to our new text File.
We will not write the %TrimmedCurrentLine%, because we would then miss out all the tabs that we previously trimmed from the both the beginning and the end of the Line.
When writing the CurrentLine to our new text File, we need to make sure we have selected the option append Content, that way it will not erase each previous Line we have written in order to write the CurrentLine.
The loop has ended, our job is complete!!
Needless to say that you could always customize this Job and get it to read a List of Files, and for each File in that List get it to clean its content from the empty rows, or even replace the text File instead of saving the cleared text to another file!
Post new comment