Here is how I did it:
<flow name="stateFileFlow" doc:name="stateFileFlow"> <file:inbound-endpoint connector-ref="input" path="/path" doc:name="File"> <file:filename-regex-filter pattern="(^ABC).xml" caseSensitive="true"/> </file:inbound-endpoint> <choice doc:name="Choice"> <when expression="#[message.outboundProperties['filename'] == null]"> <logger level="WARN" doc:name="Logger" message="NO FILE"/> </when> <otherwise> <logger level="WARN" doc:name="Logger" message="FILE EXISTS"/> <file:outbound-endpoint connector-ref="output" path="/path" doc:name="File"/> </otherwise> </choice> </flow>
And this is one more thing that simplifies working with an existing message:
<sub-flow name="stateFileFlow" doc:name="stateFileFlow"> <message-properties-transformer scope="invocation" overwrite="true" doc:name="Message Properties"> <add-message-property key="path" value="/path" /> <add-message-property key="format" value="dd-MM-yyyy" /> <add-message-property key="extension" value="flag" /> </message-properties-transformer> <scripting:component doc:name="asdf"> <scripting:script engine="groovy"> <scripting:text> def format = message.getInvocationProperty('format'); def path = message.getInvocationProperty('path'); def fileName = new Date().format(format) + "." + message.getInvocationProperty('extension'); def filePath = path + File.separator + fileName; def exists = new File(filePath).isFile(); message.setProperty('exists',exists, org.mule.api.transport.PropertyScope.OUTBOUND); message.setProperty('filename',fileName, org.mule.api.transport.PropertyScope.OUTBOUND); return message.payload; </scripting:text> </scripting:script> </scripting:component> <choice doc:name="Choice"> <when expression="#[message.outboundProperties['exists'].toString() == 'true']"> <logger level="INFO" doc:name="Logger" message="FILE EXISTS"/> </when> <otherwise> <logger level="INFO" doc:name="Logger" message="CREATING FILE #[message]"/> <file:outbound-endpoint connector-ref="output" path="/path" doc:name="File"/> </otherwise> </choice> </sub-flow>
source share