[Index]

exists


Test if a file exists. This job will flag complete if the file exists, not complete if it doesn't, and will signal an exception if the path to the file does not exist.

Property Summary

exists The files that match the file specification.
file The file specification.
lastModified If a single file is found, this is the last modified date of the file.
name A name, can be any text.
result  
size If a single file is found, this is the size of the file in bytes, or -1 if a single file hasn't been found.

Example Summary

Example 1 A simple example checking for a single file.
Example 2 File polling.
Example 3 Using exists and processing the files found.

Property Detail

exists

AccessREAD_ONLY
RequiredR/O.

The files that match the file specification.

file

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredYes.

The file specification. The file specification can contain wild card characters.

lastModified

AccessREAD_ONLY
RequiredR/O.

If a single file is found, this is the last modified date of the file.

name

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

A name, can be any text.

result

AccessREAD_ONLY

size

AccessREAD_ONLY
RequiredR/O.

If a single file is found, this is the size of the file in bytes, or -1 if a single file hasn't been found.


Examples

Example 1

A simple example checking for a single file.

<oddjob id="this">
    <job>
        <exists file="${this.args[0]}/test/io/reference/test1.txt"/>
    </job>
</oddjob>

Example 2

File polling.

<oddjob id="this" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
    <job>
        <sequential name="The Classic File Polling Example">
            <jobs>
                <scheduling:retry limits="${timer.current}">
                    <schedule>
                        <schedules:interval interval="00:00:02"/>
                    </schedule>
                    <job>
                        <sequential id="echo-when-file">
                            <jobs>
                                <exists id="check" name="Check File Exists" file="${work.dir}/done.flag"/>
                                <echo>Found ${check.exists[0]}</echo>
                            </jobs>
                        </sequential>
                    </job>
                </scheduling:retry>
            </jobs>
        </sequential>
    </job>
</oddjob>

Example 3

Using exists and processing the files found.

<oddjob id="this">
    <job>
        <sequential name="Find Files">
            <jobs>
                <exists id="exists" file="${this.args[0]}/test/io/reference/test*.txt"/>
                <foreach id="found">
                    <values>
                        <value value="${exists.exists}"/>
                    </values>
                    <configuration>
                        <xml>
                            <foreach id="found">
                                <job>
                                    <echo>found ${found.current}</echo>
                                </job>
                            </foreach>
                        </xml>
                    </configuration>
                </foreach>
            </jobs>
        </sequential>
    </job>
</oddjob>


(c) R Gordon Ltd 2005 - Present