This recent thread brought up the subject of allowing user regexes within _FileListToArrayRec. guinness then suggested using a callback function so that users could do even more specific selection. As a result I have developed a Beta version of the UDF adding such functionalities - and also added the option to return a 2D array when using a custom function, something that has been a frequent request in the past.

The main changes to the UDF code are as follows:
- 1. The UDF will now accept a user-defined regex in any of the 3 sections of the $sMask parameter - such a regex must be enclosed in double colons ( ::regex:: ) to distinguish it from a normal path/wildcard string. No error checking is done on the regex itself - the user must ensure that it is correct.
- 2. The main UDF will now accept a function in place of the $sMask parameter and internally has separate sections for running this "user function" and "normal" code to avoid any slowdown when used without a user function - combining the two meant that at least one If had to be added to each item parsed, which increased the execution time by about 5%. Note that when used with a user function, the $sMask parameter is forced to "*" (all items on the path with no exclusions) and the $iReturn parameter only defines whether files and/or folders are to be returned (the user function must deal with all other restrictions). The $iRecur parameter still works as before, but the $iSort & $iReturnPath parameters are ignored (the former because it can only work on 1D arrays (see point 4 below), while the user function must determine the latter). This was done to ensure that the internal UDF code runs as fast as possible because calling the user function for each returned item can obviously add significantly to the overall execution time.
- 3. The user function must accept 3, and only 3, parameters (the full path, name and attributes of the item) and must return the data to be included in the final returned array - if nothing is to be added, then the @error macro must be set. Otherwise there is no restriction on the user function itself - although as it is run on every item on the path, it should be as fast as possible.
- 4. If a user function is passed to the UDF, an added UDF parameter ($iUserRet_Cols) comes into play. This determines the number of columns in the returned array - the UDF defaults to a 1D array but setting the parameter to a higher value will return a 2D array with that number of columns. Obviously the user function must return suitably formatted data to be added to the return array - a simple string if the return array is 1D; an array with sufficent elements to fill the columns of a 2D return array. Note that if the number of elements in the array passed by the user function does not match the defined return array, then nothing is added.
As a result of all thesse changes, there is almost no change to the execution speed of the UDF in "normal" mode, the "direct regex" mode can make the return list more accurate, and there is now a very flexible "user function" option allowing experienced users to fine-tune the return and add further data.

Here is the Beta function with a short example included:

Comments on the utilty and implementation of the new functionalities would be most welcome.

M23