Alteryx Designer Desktop Discussions

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

Automatically change Input File directory each time the workflow is run

coren
5 - Atom

I built a workflow to pull in all of the .txt files from a specific location and translate the information to an output file format that I need.  What I'm looking to do now is the dynamically change the input location for these files each time I run the workflow.  For instance, I have files in a location C:\User\Locations\Name\In\*.txt.  I want to replace the "Name" portion of that location with a different "Name".  The directory path will be exactly the same otherwise.  By doing this, it will allow the user to specify different locations before kicking off the workflow.  Then the workflow will be able to pull files from the different locations to process.  I could just save the workflow multiple times and change the input path each time, but I'm looking to avoid storing multiple versions of the workflow for each slightly different directory "Name."

 

Any suggestions?

 

My thought is that I need ot build a macro that allows a user to input an answer to a question (via text box) that replaces that specific section of the directory string.  But, I'm at a loss on how to do that.  There may also be a better way.

3 REPLIES 3
dataMack
12 - Quasar

There are a few ways you could accomplish this (as with everything in Alteryx), and the best choice is going to be up to your specific intended use.

 

Going the macro/analytic app route, under the Interface tool category, you would wire a 'Folder browse' tool to your input via an action tool (will get added automatically).  This would allow a user to specific a location when it gets run.

 

If you want to hit multiple locations in a given run, you could use a Dynamic Input tool to change the locatons.

coren
5 - Atom

I don't understand how the file browse would work (or does work).  I'm relatively new to Alteryx.  Every time I try to run it, I get an error about an unknown file type.  My current workflow begins with an Input File that specifies one specific file location, such as C:\Users\Name\In\*.txt.

 

Every time I run this workflow, I want to be able to simply type a new "Name" rather than navigating to another directory.  The macro or app or whatever should be smart enough to just replace the "Name" in the directory string with the "Name" that I specify as my answer to a question.  I also have a couple of REGEX expressions (via Formula tool) that reference the full file path.  I would need those dynamically replaced as well when I type the "Name" in before the workflow begins.  Is anything like this possible?  It might be a little more in depth than what's possible to explain via messaging.  Thanks in advance for any help!

david_fetters
11 - Bolide

Hey Coren,

 

You can use a textbox as an input control and use the action tool to replace the filepath on each run.  Here's a picture of what the setup looks like:

Capture.PNG

Just set up your input tool to have a file name/path that works as its default.  The Formula uses the value from the text input tool to update the string containing your file path.  You can do the same thing with the regex or formula tools, just make sure you click on the exact "value or attribute you wish to update" with the formula (i.e. you must click on the file path there to have the formula change the file path, otherwise it doesn't know what to change).  You can also add conditional logic to the formulas you use here.

 

If you're attempting to read .txt files, you may want to make sure that your Input tool is setup to read the proper format.  If the .txt files are just CSV's, then the standard .CSV setting for the input tool should work fine.  If it is just a large string of text (e.g. a news article or other 'wordy' document) you may want to tweak the settings on the input tool:

Capture2.PNG

 

The key changes I made are:

- setting delimiter to '\0' which is essentially no delimiter (so that your text does not get split into separate fields)

- changing field length from '256' to '10000' (so that your text file does not get cutoff after 256 characters)

- Deselect 'First Row Contains Field Names' because if you're reading a plain text file, there are no field names.

 

Hope this helps!

Labels