Welcome to the Alteryx Knowledge Base
Created/Edited -
This is the second article in the series of using batch files to rename, move, and delete files. This workflow will create a .bat file which you can use in workflows that use the files you specify in this workflow to move to another directory.
Moving Files
Creating the Batch file workflows:
Tools needed in order of use: (1)Directory Input, (2)Select, (3)Formula, (4)Summarize, (5)Output Tools.
Directory Tool (1) –
- Browse to the file or files you are looking to change
Select Tool (2)–
- Fields you will need are Fullpath, Directory, and File Name
Formula Tool (3)– Output Fields Created: Command and Batch File.
- Create a new field, Command (String) – This is the field you want to build your command.
- Note -The directory that you want to move the files to can be hard coded by adding the directory straight into the function or you can append another directory from another Directory tool before adding to the Formula Tool. In the sample, we hard coded the directory
- Expression:
'Move '+ '"'+[FullPath]+ '"'+ ' ' + + '"'+ 'C:\Users\jdoe\Documents\Sample Data\Command Line Move'+ '"'
- Sample Output - Move "C:\Users\jdoe\Documents\Sample Data\Command Line Test\$200.xlsx" "C:\Users\jdoe\Documents\Sample Data\Command Line Move"
- Create a new field,Batch File (String) – You will take the Directory field from the Directory Input and add a name of what you want the Batch File to be.
- Expression:
[Directory]+'Moving_files.bat'
- Sample Output - C:\Users\JDoe\Documents\Sample Data\Command Line Test\Moving_files.bat
- Expression:
Summarize Tool (4) –
- Select the Command field and the action will be to concatenate using a separator as .
- select the Batch file and the action will be First.
- You can rename the Output fields if you choose as it will change the fields to Concat_Command and First Batch File.
Output Tool (5) –
- Browse to save file as any name you want (you will be replacing this name). You will want to use the Save as type: (.csv) and add .bat to end of the name. We want to transform that txt file to a bat file.
- In the Delimiters Row in the Options section add \0 as the delimiter.
- Select Take/Table Name From Field and choose Change Entire File Path.
- Select the First_Batch file (or name you called the field) in the Field Containing File Name or Part of File Name and unselect Keep Field in Output.
Adding Batch File to Your Workflow:
The last step is toadd this batch file to the Events tab in a Workflow that you want to move the file or files you have chosen in the .bat file in the Configuration window:
- Select Add > Run Command> Run Event When> After Run>
- Command: Browse to the bat file and click Ok.
See attached Sample Workflow.