Home > Alteryx > Unzip a file in Alteryx

Unzip a file in Alteryx

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

Alteryx Unzip File Path
2. Use a formula tool to write the unzip command. The field can be called cmd. For example:

“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)

Alteryx Unzip Formula Tool

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.

Alteryx Unzip Command

This is what each line of the script is doing:

Alteryx Unzip Command Explanation

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.

Alteryx Unzip Run CommandTool


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]

This is what the Alteryx engine directory looks like once the workflow has run, with the actual file inside the Extract folder:
Alteryx Unzip Directory

I created this as a macro, with the full workflow here.

Alteryx Unzip Macro

Categories: Alteryx Tags:
  1. Alicia
    October 19th, 2016 at 09:58 | #1

    Thanks Awatson… Well explained. Thanks for sharing.

  2. Nga Nguyen
    April 6th, 2017 at 19:44 | #2

    How do you zip multiple files? I have a few output that I want to combine into one single zip file.

    • awatson
      April 6th, 2017 at 20:16 | #3

      It looks quite straightforward, to extract the letter ‘e’ is used, to compress the letter ‘a’ is used. The middle of this thread, http://cects.com/automate-compression-tasks-cli/, gives an example and there are multiple other similar examples on the internet

  1. No trackbacks yet.