Every action starts stepwise. Calling a grouped action executes as you would expect and immediately returns to the previous execution state when it finishes running for all selected files.
Think of it this way. If you have three selected files:
Action 'A' processes every statement for all selected files in parallel.
'A' runs 'D' grouped.
'D' is run in its entirety for each of the three files. (Three complete executions of 'D'.
Control returns to 'A' where it again processes every statement for all three files in parallel.
Many times slices of code which you are running grouped can more effectively be handled by constraining which files are executed. As an example say you want to look for Title fields which start with 'The the'. You want to remove the extra 'the' and if and only if the condition was met you want to rename the files:
1: Test if the Title field starts with "The the " case insensitive (Set result and Variable 0)
2: Ignore files where Variable 0 is false
3: if true
4: Replace prefix of "The the" in the Title field with "The·"
5: Rename Files (My Template) *** The template does not exist
6: Restore Initial Set of Files
7: endif
Line 1 tests all selected files to see if the Title field starts with 'the the'. For every file Variable 0 is set to true (1) or false (0). This is a single test. If you have 10 files selected it is processed once as opposed to ten times if running grouped.
Line 2 constrains the set of selected files to those which have a value of true in Variable 0. Yate always requires that at least one file is available stepwise. For this reason if 'no files' satisfy the condition nothing is modified. For that reason it is critical that you always test if the statement worked.
Line 3 tests if the previous statement worked. If true, at least one file met the required condition.
Line 4 replaces the text only on those files which met the criteria.
Line 5 renames those files and only those files which met the criteria.
Line 6 restores the initial set of files so that subsequent statements outside the if-endif construct will again have all of the initially selected files available.
Regardless as to how many files were selected, the above code will only run once. If you take out statements 2 and 6 and run the sequence grouped it will work the same. However if you have 100 files selected it will execute 500 statements as opposed to 7.
There are times where ignoring files is simply too cumbersome as what you might want to execute is too complicated as it contains numerous flow control sequences. In cases such as these you can still limit the number of calls which take place. Assume that an empty Genre field requires that you perform a variety of functions which must be run grouped:
1: Test if the Genre field is empty (Set result and Variable 0)
2: Run inline action 'Fix empty Genres' grouped if Variable 0 is true
3:
4: Start Fix empty Genres
5: ' Do whatever you wish
Line 1 sets Variable 0 to true if Genre is empty, otherwise false
Line 2 executes inline action 'Fix empty Genres' grouped for each file which has an empty genre. The action called does not have to be inline. Inline actions are a good way to keep code snippets contained in the same file where they have no real value to be stored in a separate action 'file'.
The 'variable test' feature on Run statements and the statements in the File Availability category allow for a number of different scenarios to limit the number of statements that are executed.
Hopefully this helps.
|