I question often seen on the Alteryx forums is how to unzip a file in Alteryx.
In an earlier post I covered how to use the Alteryx Run Command tool to publish a Tableau Data Extract to the Tableau Server in an Alteryx workflow using TabCmd.
This post is similar but is showing how to unzip using the Run Command. The Run Command tool is able to call exe programs, meaning anything possible by exe is possible within Alteryx.
Credit to this solution needs to be given to jdunkerley79 who supplied the solution in the Alteryx forum: http://community.alteryx.com/t5/Data-Preparation-Blending/Can-Alteryx-unzip-a-file-as-part-of-the-workflow/td-p/10604
The first thing to do is install software to unzip. Currently I’m using 7-zip (http://www.7-zip.org/). This can be called via the command prompt.
Next is how to use this in Alteryx:
1. Use a text input with the full Zip File Path to the file to unzip
“C:\Program Files\7-Zip\7z.exe” e “[FilePath]” (with FilePath being the field in the text input tool containing the file path to the zipped file)
3. The unzipped file will be dropped to the directory from which it was called in the command line, hence this needs to be set before the unzip command is called. Using text inputs before and after the Select cmd field will enable us to set the directory within the command line. Remember in the command line a directory must be referred to via it’s mapped letter, not via the UNC \\server\directory Therefore we use pushd and popd to temporarily map directories.
This is what each line of the script is doing:
4. Notice all of the fields going to the Union tool are called ‘cmd’.
5. We have now created the script and it can be loaded into the Run Command tool. Loading a script into the Run Command tool automatically creates and runs a .bat file, which effectively is the script. This file just requires naming and subsequently calling in the Run Command tool…which actually is far simpler than I make it sound.
a. The union field is the only thing taken into the Run Command tool – i.e. only the script, no other fields.
b. The Write Source, prominently (and perhaps misleadingly…) called Output is where the script is ‘saved as’ a .bat file
c. In this example we save it to the Alteryx temp (%temp%) directory. Set it to be file type csv, first row doesn’t contain field names and Never Quote Output Fields
d. As we have now created the .bat file we now call it in the Run External Program Command section.
e. Finally we created the file ziplist.txt in the script, containing the name of the file unzipped – we need to take this out of the Run Command tool to use in the workflow. To take a value out of the Run Command tool use the Read Results section and open the file in the Input section. This can also be a csv.
f. Note: as none of these Output and Input files exist while creating the Run Command you’ll be presented errors – these should go away when running the workflow.
6. The next step is to create and output the file path of the unzipped file. The formula tool is used to create the file path of this file. We put the unzipped file in the Alteryx engine temp directory in a new folder called Extract. The name of the file is taken from the ziplist.txt output from the Run Command tool. Therefore our formula is:
[Engine.TempFilePath] + ‘Extract\’ + [Field_1]
I created this as a macro, with the full workflow here.