HOWTO: Use Scenarios to Automate Work
We introduced scenarios in the HandyFile Find And Replace so that you can get rid of the monotonous operations that involve searching and replacing many different portions of text in multiple files. Let us consider an example of cleaning HTML files saved from within Microsoft Word.
We will want to:
- remove comments containing intrinsic information specific to the Word;
- clean the HTML tag;
- remove the Office
There are much more Word dirt in the HTML but we shall limit our example to these searches.
We start by opening the Scenario editor by clicking the Advanced Search button and selecting Manage Scenarios from the menu.
In the Scenario dialog, create a new scenario by clicking the New button. Type the name of the new scenario, for example, Clean up Word HTML.
After the new scenario is created, start adding actions to it.
- Click the button Add Action and give it a name for the first action, for example: Remove comments.
- We shall need regular expressions to cover all comments in a file.
So we check the Regular expressions option and type the following text in the Find what field:
\<\!\-\-is the comment opening tag;
.#(any character + match 1or more times non-greedy) means "match all further text but stop before the next symbol in the expression (non-greedy)";
\-\-\>is the comment closing tag.
Please note that you should escape all non-alphanumeric symbols when searching with regular expressions.
As we want to remove comments, we leave the Replace with field blank.
- To delete SPAN tags, we create a new action and also use regular expressions but more
complex for the Find what field:
#lang\=\w#\-\w#stands for the LANG attribute with the language abbreviation;
style\=\'mso.#\'matches any style attribute starting from any
(.#)is the tag inner text that we must preserve.
We replace the found text with the tag inner text:
For the sake of brevity, we shall omit the description of "monkey-see-monkey-do" button clicks.
- To delete tags <o:p>, we do not need regular expressions as they always
have only one form:
- To clean the HTML tag, we need regular expressions again:
Escapes are generally optional in the replace field.
And finally, we shall remove the Office
\1is a replacement expression. To insert \1 literally, you would have to type:
We have now created a new scenario. Click the Save and Activate button. The Files and Text Tab will change to Advanced mode showing the scenario name.
Now do the final preparations:
- Specify the folder you want to search for files. For example:
- Set mask(s) of the files that you want to find. For example:
- Click the Replace button.
Don't forget you can run HandyFile (and Text Workbench) from the command line specifying the name of a scenario by using the parameter: