Changes the modification time of a resource and possibly creates it at the same time. In addition to working with a single file, this Task can also work on resource and resource collections (which also includes directories). Prior to Ant 1.7 only FileSet or Filelist (since Ant 1.6) have been supported.
Attribute | Description | Required |
file | The name of the file. | Unless a nested resource collection element has been specified. |
millis | Specifies the new modification time of the file in milliseconds since midnight Jan 1 1970. | No--datetime takes precedence, however if both are omitted the current time is assumed. |
datetime | Specifies the new modification time of the file. | |
pattern | SimpleDateFormat-compatible pattern string. Defaults to MM/DD/YYYY HH:MM AM_or_PM or MM/DD/YYYY HH:MM:SS AM_or_PM. Since Ant 1.6.3 | No |
mkdirs | Whether to create nonexistent parent directories when touching new files. Since Ant 1.6.3 | No, default false. |
verbose | Whether to log the creation of new files. Since Ant 1.6.3 | No, default true. |
You can use any number of nested resource collection elements to
define the resource for this task and refer to resources defined
elsewhere. Note: resource passed to this task must implement
the org.apache.tools.ant.types.resources.Touchable
interface, this is true for all filesystem-based resources like those
returned by path, fileset ot filelist.
For backwards compatibility directories matched by nested filesets will be "touched" as well, use a <type> selector to suppress this. This only applies to filesets nested into the task directly, not to filesets nested into a path or any other resource collection.
Since Ant 1.6.3, a nested
mapper can be specified. Files specified via nested
fileset
s, filelist
s, or the file
attribute are mapped using the specified mapper. For each file mapped,
the resulting files are touched. If the original file exists its
timestamp will be used. Otherwise the task settings (millis
,
datetime
) take effect.
<touch file="myfile"/>
creates myfile
if it doesn't exist and changes the
modification time to the current time.
<touch file="myfile" datetime="06/28/2000 2:02 pm"/>
creates myfile
if it doesn't exist and changes the
modification time to Jun, 28 2000 2:02 pm (14:02 for those used to 24
hour times).
<touch datetime="09/10/1974 4:30 pm"> <fileset dir="src_dir"/> </touch>
changes the modification time to Oct, 09 1974 4:30 pm of all files and directories
found in src_dir
.
<touch file="myfile" datetime="06/28/2000 2:02:17 pm"/>
creates myfile
if it doesn't exist and changes the
modification time to Jun, 28 2000 2:02:17 pm (14:02:17 for those used to 24
hour times), if the filesystem allows a precision of one second - a
time close to it otherwise.
<touch file="foo"> <mapper type="glob" from="foo" to="bar" /> </touch>
creates bar
if it doesn't exist and changes the
modification time to that of foo
.