Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Capturing the Source File Name from a Macro Input

daniel_mmi
9 - Comet

I would like to configure a macro to write the input file name into a field, capturing the file name from the macro input. I can't rely on the 'Output File Name as Field' option being used, since the file input is outside the scope of the macro. I was hoping there was some sort of function that would parse the source filename from a data stream, but have as yet been unable to find it.

 

Screen shot attached below, for general reference:

Filename_from_macro_input.PNG

 

Thanks,

-Dan

8 REPLIES 8
JordanB
Alteryx
Alteryx

Hi Dan,

 

Is the input file outside the macro changing? If so the input file should automatically update the macro input and change the file name field if you choose the 'Output File Name as Field' option. I have tested this and it seems to work for me. 

 

Alternatively there is the field info tool within the developers tab which produces the source file you referenced below. You could then parse the file name using reg-ex or text to column tool from there. 

 

Best,

 

Jordan Barker

Client Service Representative 

 

daniel_mmi
9 - Comet

Thanks, Jordan. That did it.

 

Since I couldn't guarantee the user would have the file name included in advance, I used the Field Info tool as you suggested. From there, I just had to select transpose the Field Info results, then parse the file name from the path. In order to get it back into the output file, I populated the desired _FileName field with "path", then used the Find and Replace tool to replace the word "path" in the _FileName field with the actual file name, from the reference table.

 

Import_and_Standardize.PNG

JordanB
Alteryx
Alteryx

Excellent! Good work on the rest of the workflow!

neil_randall
7 - Meteor

Would you please kindly share the source code for this? I have been wanting to complete a similair task.

daniel_mmi
9 - Comet

This was in the middle of a larger workflow, so beg your pardon if it behaves strangely.

 

All the parts are there, though, and the functionality should be pretty straightforward.

AndyC
Alteryx Alumni (Retired)

 

Posted in error! 

 

Andy Cooper
Senior Solutions Engineer - EMEA
Alteryx
Raghu_s
8 - Asteroid

Hello! 

I have a simple macro that reads a folder that has 20+ .txt files with inconsistent schema. just an additional column in few files. So I have used this macro for a while to get this data in a common table. Now I require the file names for each record to be appended to extract some attribution information. when I try to add the filename feature in input tool set inside the macro, the output just appends the template name that's being pointed out rather than the actual file names. 

 

am trying to make use of your macro not am not able to utilize as am very new when it comes to macros. Can you breakdown your WF or give me push to accomplish my ask? 

 

looking forward. 

JordanB
Alteryx
Alteryx

Hi @Raghu_s

 

Inside of your macro your input tool and interface designer (View>Interface Designer) need to look like this:

 

part1.PNG

 

This will append the file name to each row in that txt file. Make sure you add a browse tool outside the macro to see all rows of data.

 

Best,

 

Jordan Barker

Labels
Top Solution Authors