Automation Action – File Operation | ThinkAutomation
Automation Action: File Operation
Perform various operations on files & folders.
Create new folders, copy, move, rename, check exists, delete files and get file information.
Use this Action to create new folders or to copy, move, check if files exists, rename & delete files and get file information. You can also use this action to generate an SHA256 hash (checksum) for any file.
Select the Operation Type:
- Create Folder
- Copy File
- Move File
- Delete File
- Rename File
- Check If File/Folder Exists
- Get SHA256 Hash For File
- Get File Size
- Get File Date
- Get File Version
- Read File To Base64 String
- Write Binary File From Base64 String
- Append To Filename
- Prefix Filename
- Get Folder Contents
Depending on the Operation Type enter the Folder, File Name, To Folder & To File Name.
You can assign the result to a variable. Select from the Assign To Variable list. The variable will be set to the new folder and file name depending on the Operation Type. For example, for the Create Folder operation the variable will be assigned to the new folder name. For the Copy operation the variable will be assigned the full path & file name of the new file. If the operation fails the variable will be assigned a blank string and the error will be shown in the log. The Check If File/Folder Exists operation will return the file/folder path is the file/folder exists, otherwise blank.
The Append To Filename and Prefix Filename operations allow you to append text or prefix text to existing file names. For example: If the Append Text is set to ‘abc’ and the processed filename was ‘order.pdf’ then the existing file will be renamed to ‘orderabc.pdf’.
The Copy, Move, Delete, Append To Filename & Prefix Filename operations allow the File Name to contain wildcards. If using wildcards enable the Match Files Using Wildcards option. The File Name can contain * and ? wildcard characters. When using wildcards, if multiple files are processed then the Assign To Variable will contain a list of files processed separated by commas.
For the Copy operation you can specify the To File Name (when not using wildcards). You can specify a different destination file name. If this entry is blank the original file name will be used.
For the Copy operation you can enable the Overwrite Existing option if you want existing files in the destination folder to be overwritten. If this option is not enabled and an existing file already exists then an error will raised.
The Get File Version operation returns file information in the following format:
File: D:ThinkAutomationSetup FilesThinkAutomation.exe InternalName: ThinkAutomation OriginalFilename: ThinkAutomation.exe FileVersion: 5.0.240.2 FileDescription: ThinkAutomation Installer Product: ThinkAutomation ProductVersion: 5.0.240.2 Debug: True Patched: False PreRelease: False PrivateBuild: False SpecialBuild: False Language: English (United Kingdom)
For the Create Folder operation the complete folder structure will be created if any levels do not exist. If the full folder already exists the Assign to variable will be assigned the existing folder name and no error will be reported. An error will only be reported for the Create Folder operation if the creation of a new folder fails.
The Get Folder Contents operation returns a list of files in the specified Folder and Mask. Enable the Include Sub-Folders option to include sub-folders. The Mask is optional, but can be used to restrict to certain file types. Specify a comma-separated list of masks (eg: *.pdf, *.docx).
The file list will be assigned to the Assign To variable. You can select the format of the list from the Return As list:
- Comma separated : Each path will be separated by a comma. You can use the For Each.. Comma Separated Value In action to loop through the list.
- One Path Per Line : Each path will be on a new line. Use the For Each.. Line In action to loop through the list.
- JSON : A Json array in the following format:
[ { "Path": "D:\Setup Files\ThinkAutomation.exe", "Name": "ThinkAutomation.exe", "Extension": "exe", "Size": 167815264, "Created": "2020-11-20 14:58:02", "Modified": "2020-11-20 14:58:05" }, {..}, {..} ]
If you are accessing folder/files on your network you may need to change the user name that the ThinkAutomation Message Processor Service runs under depending on your security configuration.