If - Compare files

Declaration

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

Related Topics   

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, by default, any If activity added to the Task Builder's Steps panel 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

 
PropertyTypeRequiredDefaultMarkupDescription
File ATextYes(Empty)FILEA="C:\Folder\FileA.txt"The path and file name 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 BTextYes(Empty)FILEB="C:\Folder\FileB.txt"The path and file name 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 typeText (options)YesSizeCOMPARETYPE="CRC"The criteria to use when comparing the two files. The available options are:
  • Size - 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 algorithmText (options)Yes if Compare type set to CRC/HashCRC

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:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

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 files "C:\temp2\log.txt."

Copy
<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>
<AMFILESYSTEM ACTIVITY="delete" SOURCE="C:\temp2\log.txt" />
<AMIF ACTIVITY="end" />