Alteryx Designer Knowledge Base

Definitive answers from Designer experts.
It's the most wonderful time of the year - Santalytics 2020 is here! This year, Santa's workshop needs the help of the Alteryx Community to help get back on track, so head over to the Group Hub for all the info to get started!

How to dynamically rename headers on multiple files in a directory

Alteryx
Alteryx
Created

If you have a file that doesn't have the field names in the header row but rather in the first row of data, the Dynamic Rename Tool has an option to take field names from first row of data, which allows you to rename your headers easily and dynamically.

 

But what if you have many files in a directory, all with the same problem?

 

You want to combine these two files and turn them into one clean output: 

 

 9-21-2016 4-41-07 PM.png

 

But you don't want to have to map each and every one into Alteryx and use a Dynamic Rename Tool for each one of them....

 

The solution is to wrap a batch macro around the Input Tool and Dynamic Rename Tool. This will let you read in each file individually, fix their header row and then combine them into one dataset!

 

It's a fairly simple macro: 

9-21-2016 4-09-58 PM.png

 

It accepts full file paths as the input, which are used to update the file mapped into the Input tool inside the macro. The Dynamic Rename Tool is set to accept "Dynamic or Unknown Fields" so it will pick up on any column from an input file. It then replaces the current header with the values found in the first row of data. 

 

The macro "holds" the data until all iterations have run (all files have been read in) and then unions the data together based on field names because we selected "Auto Configue by Name" as the Output Mode: 

 

9-21-2016 4-11-43 PM.png

 

To use the macro in a workflow, point a Directory Tool to the folder containing the files to be read in and then use the FullPath to feed into the macro. 

 

 See the attached workflow for an example.

Attachments