This is the third article in the series of renaming, moving, and deleting files using a batch file. This workflow will create a .bat file which you can use in other workflows that use the files you specify in this workflow to delete files.
WARNING: Please be careful using this command as it will do what it says it will do. Test thoroughly before adding to production.
Deleting Files
Creating the Batch file workflows:
Tools needed: (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.
Expression:
'DEL '+ '"'+[FullPath]+ '"'+ ' ' + + '"'+[FileName]+ '"'
Sample Output - DEL "C:\Users\dmenke\Documents\Sample Data\Command Line Test\$200.xlsx" "$200.xlsx"
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]+’Delete_files.bat'
Sample Output - C:\Users\JDoe\Documents\Sample Data\Command Line Test\rename_files.bat
Summarize Tool –
Select the Command field and the action will be to concatenate using a separator as \n.
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 to add 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.
View full article