In previous posts I’ve written about how to use the Run Command tool in Alteryx to publish a tableau extract to tableau server and how to unzip a file in Alteryx. Another great use for the Alteryx Run Command tool is to move and copy files.

To move files from a directory into another directory the following information is required:

  1. File path of file to move
  2. Destination directory

Set up the workflow in the following way:

1. Enter the above fields in a Text Input tool, creating the fields FullPath and DestinationDirectory

Alteryx Move Copy Text Input

Note: The backslash at the end of the DestinationDirectory is very important. Without that a new file would be created called Engine in D:\Alteryx.

2. Connect to a Formula tool to create the Move command. I call the field ‘cmd’. It’s recommended this is first written and tested in Notepad to ensure the command works as expected. (To copy a file edit this command expression.)

Alteryx Move Copy FormulaTool

3. Next step is to join this to a Select tool, only selecting the new ‘cmd’ field. The Run Command tool should only have one field loaded into the tool. In this case the ‘cmd’ field is loaded into the tool.

4. Add the Run Command tool to the workflow. The Run Command tool will take the command written in the field ‘cmd’ and convert it to a bat file. The Run Command tool will then call this bat file.

a. The Write Source Output is where the .bat file is created. This can be set as a .flat file or .csv –anything that’s a flat text input. (If using csv ensure there’s no delimiter set, the First Row does not Contain Field Names and Quote Output Fields Never.) In this example the file is being written to the Alteryx temp directory, %temp%. The file is called MoveFiles.bat.

b. In the Run External Program Command section we run the .bat file just created. Therefore just enter %temp%\MoveFiles.bat.

Alteryx Move Copy Run Command

When setting up the Run Command you could be presented with a few errors as the file being created doesn’t yet exist. Running the workflow should remove the errors.

The final workflow is as follows:

Alteryx Move Copy Workflow

Credit for the post also must go to s_pichaipillai on the Alteryx forum who explained how this works:

The same technique can be used to copy files, only replace the MOVE command with COPY or XCOPY.