Contact Free trial Login

To List Files Using the File Connector

The List operation returns a List of Messages, where each message represents any file or folder found within the Directory Path (directoryPath).

By default, the operation does not read or list files or folders within any sub-folders of directoryPath.

To list files or folders within any sub-folders, you can set the recursive parameter to true.

This example lists all messages in a directoryPath, without listing the contents of any sub-folders. Note that the path can be absolute, or it can be relative to a Working Directory (workingDir) set in the File configuration (through <file:config/>).

<flow name="list">
  <file:list directoryPath="~/dropFolder" />
      <when expression="#[]">
        <flow-ref name="processDirectory" />
        <logger message="Found file #[attributes.path] which content is #[payload]" />

The example above lists the contents of a folder, then uses the For Each and Choice components to handle each directory in the list differently than it handles each file.


You can use the <file:matcher> element to filter files based on the matching criteria you use for accepting or rejecting a file. Here is an example of file matching rules you can use:

Example: File Matcher
  maxSize="1024" />

All of the attributes above are optional and are ignored if not provided. They all relate to each other under an AND operator.

As the next examples show, a file matcher can be a reusable element (a named top-level element), or it can be used as an inner element that is proprietary to a particular component.

Example: Top-level, Reusable Matcher

<file:matcher name="smallFileMatcher" maxSize="100" />

<flow name="smallFiles">
  <file:list path="~/smallfiles" matcher="smallFileMatcher" />

Example: Inner, Non-reusable Matcher

<flow name="smallFiles">
	<file:list path="~/smallfiles">
        <file:matcher maxSize="100" />

For more on the capabilities of the matcher, see File Connector Documentation Reference.

Repeatable Streams

The List operation makes use of the repeatable streams functionality introduced in Mule 4. 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 on this topic, see Streaming in Mule 4.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub