【问题标题】:how to use filename-regex option in int-ftp:outbound-gateway?如何在 int-ftp:outbound-gateway 中使用文件名正则表达式选项?
【发布时间】:2015-05-09 10:36:52
【问题描述】:

我在 spring 集成项目中使用ls 命令和递归模式定义了 ftp 出站适配器。我想过滤并获取指定sub-directories 中的文件。服务器上的目录结构是:

root  
----------a\  
---------------in\  
---------------------a.op   
----------b\   
---------------in\  
---------------------b.op   

我想获取a.opb.op 文件。我将filename-regex 选项设置为([a-z]|in|.*\.op),但它不能正常工作,只过滤了第一级目录。我的适配器代码是:

 <int:inbound-channel-adapter expression="'/'" channel="inbound">
        <int:poller fixed-delay="20000"/>
    </int:inbound-channel-adapter>
 <int-ftp:outbound-gateway id="gatewayLS"
                              session-factory="ftpSessionFactory"
                              request-channel="inbound"
                              command="ls"
                              filename-regex="([a-z]|in|.*\.op)"
                              command-options="-R"
                              expression="payload"
                              reply-channel="toSplitter"/>

我该如何解决这个问题?

【问题讨论】:

  • 尝试使用\b([a-z]\\in\\.*?\.op)\b 正则表达式。
  • 感谢@stribizhev 的回复,但无法正常工作:(
  • 这个(in|.*.op)怎么样?
  • 使用(.*\.op|^[^\.]+$)作为模式返回什么?

标签: spring ftp spring-integration


【解决方案1】:

filename-regex="([a-z]|in|.*\.op)"

在递归期间应用正则表达式。

鉴于您的树结构:

第一个ls,返回[a, b]。

这些由第一个可选的正则表达式元素 [a-z] 传递。

第二个和第四个ls返回in,由第二部分传递。

第三个ls返回a.op,由最后一部分传递。

第五个ls返回b.op,由最后一部分传递。

【讨论】:

  • 感谢@Gary Russell 的回复,如果文件存在于目录a 中并且扩展名为.op,则返回结果。
  • 正则表达式应用于每个递归,因此它应该可以工作;我建议你使用调试器。
  • 我使用ls 命令,命令中支持文件名正则表达式选项吗?
  • 每个目录中带有.in的文件包含在结果中,我只想将.in扩展名的文件包含在结果中。
  • 没错@Gary,但是当文件存在于a 目录中时,例如:a/test.op 包含在我的结果中。
猜你喜欢
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多