This post describes how to move a file in Alteryx. To move or copy files in Alteryx use the Run Command tool.
As the name of the tool suggests the tool runs command line scripts. Therefore anything that runs on the command line can also run in Alteryx.
How to move or copy files in Alteryx
The method to move or copy a file in Alteryx is almost identical. Using the example below, simply replace the MOVE command with COPY or XCOPY.
To move or copy files in Alteryx requires two pieces of information:
- File path of file to move
- Destination directory
Set up the Alteryx workflow as follows:
1. Start the move or copy with a Text Input tool.
Enter the above fields into a Text Input tool.
This step creates the “FullPath” (#1 above) and “DestinationDirectory” (#2 above) fields.
Note: The backslash at the end of the DestinationDirectory is very important. Without the backslash a new file will be named Engine and stored in the folder D:\Alteryx. We want the file stored in the Engine folder.
2. Write the Move or Copy command in a Formula tool
Add a formula tool. Build the move / copy command line text in the Formula tool.
In this example I name the field ‘cmd’.
I strongly recommend first writing the command line text in Notepad then testing in the command line interface.
This is to ensure the command works as expected.
For those less familiar with the command line interface, type “cmd” in your machine search box should open the Command Prompt box.
This is where you run the command line scripts.
To COPY a file instead of MOVE, edit this command expression. To copy a file the expression should begin with ‘copy’ rather than ‘move’.
3. Next step is to add a Select tool
Select only the new ‘cmd’ field. Only pass one field into the Run Command tool. Here we use the ‘cmd’ field.
4. To finish the move or copy add a Run Command tool
The Run Command tool takes the command text (written in the field ‘cmd’) and converts it to a bat file. The tool then runs this bat file.
a. The Write Source Output creates the .bat file. Set this as a .flat file or .csv – any file type 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 bat file is written to the Alteryx temp directory, %temp%. The file name is MoveFiles.bat.
b. In the Run External Program Command section we run the .bat file; called MoveFiles in this example. Therefore enter %temp%\MoveFiles.bat in the Command section.
When setting up the Run Command you may notice some errors. This is likely to be because the file in the Command section doesn’t yet exist.
Simply running the workflow should remove the errors.
The final workflow is as follows: