1. Challenge:
I needed to poll the Alteryx temp directory for files, to pick up work to process.
The Directory tool is a "root" tool and runs once before all your other tools, regardless of position in the workflow, so it would never see the files.
Alteryx also has a different temp directory on each run, and the file names I was looking for were also different on each run.
The Directory tool has an interface that takes a static directory location and static file specification pattern, so I had to make a Directory tool that could take input from the stream, and run at the moment it received the stream data.
2. Solution:
The simple solution is to use a batch macro with Control Parameters, and replace the static strings representing the target directory and target file specification. I also made the sub-directories flag dynamic, whilst I was down there.
3. Value:
I can now pass [Engine.TempFilePath] into the Dynamic Directory tool. Also, I can create a unique file pattern to ensure that the processing job processes only the relevant files. I can run two instances of the general processing run, and each instance will create its own job files, and can run it's own polling routine that share the same temp directory but have their own files.
The Dynamic Directory tool is general, and I can re-use it in any situation where the files it is trying to upload are not necessarily there at the start of the run, or where the directory and/or file specification depends on data (ie a file or directory with a date in it).
Notes:
The Sub-directories field is text, and will take any common positive value like "1", "Y", "True". To get the full list or expand this, you can peep the macro and change if you need.
The macro is unlocked so you can see how the general principle can be used to make any tool dynamic.
An additional benefit is that you can do directory queries of multiple directories and/or file specifications in the same run by passing multiple records to the tool. For example, if you have files of interest that might possibly be in different places, you can find them by putting all the possible directories into the tool, one record each. Similarly, if you have multiple possible file patterns, you can pass those patterns into the tool as records.
Note: I have included an example workflow to show how the tool is used, and an example data file to push data into the example workflow.