---
schema_version: "1"
id: ea0faade84a00d5ee06338970a9a7b481b222ae4d69db0245a7ce34c89f597b8
title: To Trigger a Flow When a New File is Created or Modified
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/file-connector/latest/file-on-new-file.md
canonical_url: https://docs.mulesoft.com/file-connector/latest/file-on-new-file
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b1bf07ccbbb3ff4dceadf9afe4b4d973916319d5f0492ca5f5fef102f56e388b
description: MuleSoft Documentation Site
release: "1.5"
latest: true
---
---
product: File Connector
version: 1.5
is-latest-version: true
keywords: file, connector, trigger, listen
---

# To Trigger a Flow When a New File is Created or Modified

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Anypoint Connectors for File, FTP, and SFTP provide an **On New or Updated File** operation that
polls a directory for files that have been created or updated. A message is generated for each file
that is found.

The following strategies determine that a file is new:

- Set the **Auto delete** field to **True** to delete each file after it is processed, which causes
  all files obtained in the next poll to be considered new.

- Set the **Move to directory** field to move each file to a different directory after it is
  processed, which achieves the same effect as **Auto delete** but without erasing the file.

- Set the **Watermark** field to pick only files that have been created or updated after the last
  poll was executed.

You can also use a matcher for additional filtering of files.

Example: File Listener (On New File Trigger)

```xml
<flow name="onNewFile">
    <file:listener config-ref="file" directory="test-data/in" autoDelete="true">
      <scheduling-strategy>
        <fixed-frequency frequency="1000"/>
      </scheduling-strategy>
    </file:listener>

    <flow-ref name="processFile" />
</flow>
```

## Watermarking

For the File connector, the watermarking strategy can be used in two different modes:
`CREATION_TIMESTAMP` or `MODIFIED_TIMESTAMP`. The strategy depends on whether you want to filter
files based on their creation or modification time.

Example: Watermarking with the File Listener

```xml
<file:listener doc:name="On New File"
  config-ref="File_Config1"
  watermarkMode="CREATED_TIMESTAMP">
    <scheduling-strategy >
      <fixed-frequency />
    </scheduling-strategy>
</file:listener>
```

## Repeatable Streams

The **List** operation makes use of the repeatable streams functionality. The operation returns a
list of messages, where each message represents a file in the list and holds a stream to the file. A
stream is repeatable by default.

For more information, refer to [Streaming in Mule Apps](https://docs.mulesoft.com/mule-runtime/latest/streaming-about).
