Comments

1 comment

  • Avatar
    Jake

    Checking files and directories with the <fileTest> rule

    InstallBuilder allow to check files and directories properties through the <fileTest> rule. This rule accepts the below tests:

    • exists: Exists
    • not_exists: Does not exist
    • writable: Is writable
    • not_writable: Is not writable
    • readable: Is readable
    • not_readable: Is not readable
    • executable: Is executable
    • not_executable: Is not executable
    • is_directory: Is a directory
    • is_not_directory: Is not a directory
    • is_symlink: Is a symbolic link
    • is_not_symlink: Is not a symbolic link
    • is_file: Is a file
    • is_not_file: Is not a file
    • is_empty: Is empty
    • is_not_empty: Is not empty

    The conditions is_empty and is_not_empty above both apply to files and directories. When used over a directory, it will check if it contains any file and if used over a file, it will check its contents (size). If you want to avoid false results when checking a directory (or file) you can combine it with another fileTest rule to enforce the file type:

    <!-- We don't want an empty file to return '1' -->
    <ruleList>
     <fileTest condition="is_directory" path="${path}" />
     <fileTest condition="is_empty" path="${path}" />
    </ruleList>
    

    This will work if the <ruleEvaluationLogic> is 'and', if you need it to be 'or' to create a more complex rule, you can use a ruleGroup:

    <showInfo text="Is Windows or directory ${path} is empty">
      <ruleEvaluationLogic>or</ruleEvaluationLogic>
      <ruleList>
         <!-- This ruleGroup is equivalent to a is_directory_and_empty test -->
         <ruleGroup>
           <ruleList>
             <fileTest condition="is_directory" path="${path}" />
             <fileTest condition="is_empty" path="${path}" />
           </ruleList>
         </ruleGroup>
      </ruleList>
    </showInfo>
    

Please sign in to leave a comment.