Checking files and directories with the fileTest rule

asked 14 Sep '11, 10:13

Jake's gravatar image

Jake ♦♦
accept rate: 98%

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' -->
 <fileTest condition="is_directory" path="${path}" />
 <fileTest condition="is_empty" path="${path}" />

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">
     <!-- This ruleGroup is equivalent to a is_directory_and_empty test -->
         <fileTest condition="is_directory" path="${path}" />
         <fileTest condition="is_empty" path="${path}" />

answered 14 Sep '11, 10:14

Jake's gravatar image

Jake ♦♦
accept rate: 98%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 14 Sep '11, 10:13

Seen: 1,483 times

Last updated: 14 Sep '11, 10:14