= 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
:tabs-sync-option:
: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 the folder.
It is based on the project https://github.com/gmethvin/directory-watcher[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
// component headers: START
include::partial$component-endpoint-headers.adoc[]
// component headers: 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 a 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");
----

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