= File Watch Component
:doctitle: File Watch
:shortname: file-watch
:artifactid: camel-file-watch
:description: Get notified about file events in a directory using java.nio.file.WatchService.
:since: 3.0
:supportlevel: Stable
:component-header: Only consumer is supported
//Manually maintained attributes
:camel-spring-boot-name: file-watch

*Since Camel {since}*


*{component-header}*

This component can be used to watch file modification events in folder. It is based on https://github.com/gmethvin/directory-watcher[gmethvin/directory-watcher].

== URI Options

// component-configure options: START

// component-configure options: END

// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
// component options: END

// endpoint options: START

// endpoint options: END


== Examples:

=== Recursive watch all events (file creation, file deletion, file modification):

[source,java]
----
from("file-watch://some-directory")
    .log("File event: ${header.CamelFileEventType} occurred on file ${header.CamelFileName} at ${header.CamelFileLastModified}");
----

=== Recursive watch for creation and deletion of txt files:

[source,java]
----
from("file-watch://some-directory?events=DELETE,CREATE&antInclude=**/*.txt")
    .log("File event: ${header.CamelFileEventType} occurred on file ${header.CamelFileName} at ${header.CamelFileLastModified}");
----

=== Create snapshot of file when modified:

[source,java]
----
from("file-watch://some-directory?events=MODIFY&recursive=false")
    .setHeader(Exchange.FILE_NAME, simple("${header.CamelFileName}.${header.CamelFileLastModified}"))
    .to("file:some-directory/snapshots");
----

== Message Headers

The following headers are supported by this component:

=== File Watch consumer only

[width="100%",cols="10%,90%",options="header",]
|===
|Header |Description

|`CamelFileEventType` |Type of event. Possible values: CREATE, DELETE, MODIFY.
The java type of this header is String

|`CamelFileName` |Name of the consumed file as a relative file path with offset from the
starting directory configured on the endpoint.

|`CamelFileNameOnly` |Only the file name (the name with no leading paths).

|`CamelFileAbsolute` |A `boolean` option specifying whether the consumed file denotes an
absolute path or not. Should normally be `false` for relative paths.
Absolute paths should normally not be used but we added to the move
option to allow moving files to absolute paths. But can be used
elsewhere as well.

|`CamelFileAbsolutePath` |The absolute path to the file. For relative files this path holds the
relative path instead.

|`CamelFilePath` |The file path. For relative files this is the starting directory + the
relative filename. For absolute files this is the absolute path.

|`CamelFileRelativePath` |The relative path.

|`CamelFileParent` |The parent path.

|`CamelFileLastModified` |A `Long` value containing the last modified timestamp of the file.
|===


include::spring-boot:partial$starter.adoc[]
