Combining or Modifying Conditions
In this section, we will explore how to combine multiple conditions into longer statements and how to apply a negative match to conditions. With just a basic understanding of how conditions can be combined or modified, you will quickly learn how to craft complex ones that target exactly the data you need.
Marking a Condition as a Negative
By using a !, you can apply a negative to many conditions. This is useful when you want to use a condition to exclude files, rather than target them.
Here are some examples of negative matches that will exclude files.
Match files that do NOT have the Space Launch tag:
# Match files that do NOT have the tag "Space Launch" (case sensitive)
!HAS_TAG("Space Launch")
Match files that do not start with mars (lowercase):
# Match files that do NOT have the name "mars*.*" (case sensitive)
!FNMATCH("mars*.*",NAME)
Match files that do not have the Project Apollo label:
# Match files that do NOT have the label "Project Apollo"
!HAS_LABEL(LABEL('Project Apollo'))
Build a Conditional Statement Using Conditions
Objective conditions do not need to be singular. You can combine them with if or or statements and even ( ). In this section, we will review three different conditions that also leverage conditional statements.
| Each of the examples uses ⇐ or >= conditionals for date statements, meaning that the times referenced will also match the condition. Remove the = if you don’t want to match the referenced time, and match only the value that precedes or follows it. |
Example 1
Desired match: Live files only (no snapshot data), used within the last 6 months with the "Space Launch" tag OR contained within the jupiter folder and used within the last 30 days.
Equivalent condition written in Hammerscript:
IS_LIVE AND ((LAST_USE_AGE<=6*MONTHS AND HAS_TAG("Space Launch")) OR (FNMATCH("*/jupiter/*",PATH) AND LAST_USE_AGE<=30*DAYS))
Example 2
Desired match: All files that start with mars (all lowercase) OR files with the orbit extension that were created less than 60 days ago.
Equivalent condition written in Hammerscript:
FNMATCH("mars*.*",NAME) OR (CREATE_AGE <= 60*DAYS AND FNMATCH("*.orbit",NAME))
Example 3
Desired match: Live files last used between 6 months and 1 year ago.
Equivalent condition written in Hammerscript:
IS_LIVE AND (LAST_USE_AGE>=6*MONTHS AND LAST_USE_AGE<=1*YEARS)