简体   繁体   English

使用 Apache Camel 删除文件

[英]Deleting the files using Apache Camel

I just tried out a Camel route to move such files which are modified in the last 10 days from input directory to output directory and after the transfer of all the files from input directory are deleted as I set the option delete=true.我刚刚尝试了一条骆驼路线,将过去 10 天内修改的此类文件从输入目录移动到 output 目录,并在从输入目录传输所有文件后删除,因为我设置了选项 delete=true。

Date tenDaysBack = new Date(System.currentTimeMillis() - 10*8640000);
from("file:data/input?noop=true")
    .filter(header("CamelFileLastModified").isGreaterThan(tenDaysBack))
    .to("file:data/output");

This worked fine.这工作得很好。 But now what I want to do is keep the files that were modified in the last 10 days in the input directory only and delete the rest.但现在我要做的是将过去 10 天内修改的文件仅保留在输入目录中,并删除 rest。 How can we do it using Camel?我们如何使用骆驼来做到这一点?

Use parameter filterFile option of File component instead of filter EIP使用 File 组件的参数filterFile选项代替过滤 EIP

To look for file older than 10 days, try filterFile=${date:file:yyyyMMddHHmm} <= ${date:now-240h:yyyyMMddHHmm}要查找超过 10 天的文件,请尝试filterFile=${date:file:yyyyMMddHHmm} <= ${date:now-240h:yyyyMMddHHmm}

  • ${date:file:yyyyMMddHHmm} - file last modified time (up to minutes level) ${date:file:yyyyMMddHHmm} - 文件最后修改时间(最高分钟级别)
  • ${date:now-240h:yyyyMMddHHmm} - time of current minus 10 days (up to minutes level) ${date:now-240h:yyyyMMddHHmm} - 当前时间减去 10 天(最多分钟级别)

Reference: Camel File Component Camel File Language参考: 骆驼文件组件骆驼文件语言

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM