[mule-user] Getting Last Modified Time From File

17 views
Skip to first unread message

Corey Mosher

unread,
Jan 24, 2012, 3:01:11 PM1/24/12
to us...@mule.codehaus.org
I'm working with my first mule flow and want to watch a directory for files and move them to another directory naming the file with the last modified timestamp appended to the output filename. Is there a way to get that information from an input file endpoint?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Pablo La Greca

unread,
Jan 24, 2012, 4:12:38 PM1/24/12
to us...@mule.codehaus.org
Hi,

There's no way to get the last modified time from a file but if your polling frequency is not very high maybe you can use #[function:datestamp] and append that to the output file as an approximation. Here [1] you can find an example about how to use that function.

[1] http://www.mulesoft.org/documentation/display/MULE3USER/File+Transport+Reference

HTH, Pablo.

Andrew Perepelytsya

unread,
Jan 24, 2012, 5:27:45 PM1/24/12
to us...@mule.codehaus.org

I think if you change message adapter on the file connector to FileMessageAdapter (or whatever the actual name is now), and get a java.io.File object instead of a bye array, then lastModified value can be retrieved.

HTH,
Andrew

Pablo La Greca

unread,
Jan 24, 2012, 11:21:25 PM1/24/12
to us...@mule.codehaus.org
Another solution is, if you are suing streaming, you will have a ReceiverFileInputStream as payload. That class has a getCurrentFile() method which returns a java.io.File. You can get the last modified date from there.

It doesn't seem to be your case but if you use a working directory then you will be getting a wrong last modified date since that File object will represent the file moved to the working directory instead of the original file.

Corey Mosher

unread,
Jan 26, 2012, 11:00:42 AM1/26/12
to us...@mule.codehaus.org
Thanks for the suggestions. I decided that I don't necessarily need the last modified time as long as my inbound file endpoint is using the OlderFirstComparator. I really just need to maintain the order the files arrived so I think this will do it combined with appending the current timestamp to the end of the filename once I move it.

Thanks

Dirk Olmes

unread,
Jan 27, 2012, 11:36:21 PM1/27/12
to us...@mule.codehaus.org
On 01/24/2012 11:27 PM, Andrew Perepelytsya wrote:
> I think if you change message adapter on the file connector to
> FileMessageAdapter (or whatever the actual name is now), and get a
> java.io.File object instead of a bye array, then lastModified value can
> be retrieved.

That's configuring a service override to use the
org.mule.transport.file.FileMuleMessageFactory. And make sure that
streaming=false on the endpoint.

-dirk

Reply all
Reply to author
Forward
0 new messages