If - Compare Files

Declaration

<AMIF ACTIVITY="comparefiles" FILEA="text" FILEB="text" COMPARETYPE="text (options)" HASHTYPE="text (options)">

Description:

Compares two files using the specified criteria and returns TRUE if the values match or FALSE if they don't. If the result evaluates to TRUE, the task will execute the block of steps immediately following this step up until an End if step is encountered. If the result evaluates to FALSE, the block will be skipped and execution will proceed directly after the End if step (or if an Else step is encountered, the task will execute that block of steps instead, up until an End if step is encountered).

Note: All If activities must be followed at some point with an End if step to mark the end of the code block that is to be executed if the expression is true. For ease of use, any If activity added to the Steps pane of the task builder is always followed by an End if activity.

Practical Usage

A conditional statements that can perform different actions during the course of a task depending on the result of a file comparison.

Parameters

General

Property

Type

Required

Default

Markup

Description

File A

Text

Yes

(Empty)

FILEA="C:\Folder\FileA.txt"

The path and filename of the file to compare against the one specified in the File B parameter. Click the Folder icon and navigate to the desired file or enter the path and file name manually in the provided field.

File B

Text

Yes

(Empty)

FILEB="C:\Folder\FileB.txt"

The path and filename of the file to compare against the one specified in the File A parameter. Click the Folder icon and navigate to the desired file or enter the path and file name manually in the provided field.

Compare type

Text (options)

Yes

Size

COMPARETYPE="CRC"

The criteria to use when comparing the two files. The available options are:

  • Size (Default) - The file size will be compared.

  • CRC/Hash - The checksum algorithm will be compared.

  • Creation date - The creation date will be compared.

  • Modified Date - The last modified date will be compared.

  • Last accessed date - The last accessed date will be compared.

  • Attributes - The file attributes will be compared.

Checksum algorithm

Text (options)

Yes if Compare type set to CRC/Hash

CRC

HASHTYPE="MD5"

The algorithm to use when comparing the two files. This parameter is available only if the Compare type parameter is set to CRC/Hash. The available options are:

  • CRC

  • MD5

  • SHA1

  • SHA256

  • SHA356

  • SHA512

Description

Error Causes

On Error

Example

NOTE: The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.

Description: Compare file "C:\temp1\log.txt" with file "C:\temp2\log.txt". Compare hash values. Use the MD5 algorithm. If hash values match, delete file(s) "C:\temp2\log.txt".

 

<AMIF ACTIVITY="comparefiles" FILEA="C:\temp1\log.txt" FILEB="C:\temp2\log.txt" COMPARETYPE="crc" HASHTYPE="md5">

     <AMFILESYSTEM ACTIVITY="delete" SOURCE="C:\temp2\log.txt" />

</AMIF>