简体   繁体   English

通过在pentaho中搜索字符串从目录中获取文件名

[英]Get file name from a directory by searching a string in pentaho

I am going to prepare a job that has fields such as Path(DIRECTORY) and FileName. 我要准备一份具有Path(DIRECTORY)和FileName等字段的作业。 These fields value will change for every row. 这些字段的值将针对每一行更改。

Objective of my task is, I need to check whether the FileName file exists in the directory. 我的任务目标是,我需要检查目录中是否存在FileName文件。 That I did with the "File Exists" step and checked whether file exists. 我对“文件已存在”步骤进行了检查,并检查了文件是否存在。 Then I used the "Filter Rows" step and performed an operation if the file exists. 然后,我使用“筛选行”步骤并执行了一个操作(如果文件存在)。

If the file is not present in the directory, I need to check for the other files that starts with the filename value. 如果目录中没有该文件,则需要检查其他以文件名开头的文件。

Example: I have the file name as "sample.png", if the file does not exists in the directory I want to search for the files that starts with "sample..."(Eg: sample_1.png). 示例:如果目录中不存在该文件,则我的文件名为“ sample.png”。我要搜索以“ sample ...”开头的文件(例如:sample_1.png)。

Can you try the approach to 你能尝试一下

  1. fetch the list of files having sample key in the directory using wildcard expression ^sample.* in the " Get File Names " (use a ktr) 使用“ 获取文件名 ”中的通配符^sample.*获取目录中具有sample关键字的文件列表(使用ktr)

  2. Then use a filter row step to filter out the two path. 然后使用过滤器行步骤过滤掉两条路径。 True path will pass the data having the filename sample.png and the False path will pass on the files incase sample.png is not found. True path将传递文件sample.png的数据, False path将传递文件(如果未找到sample.png的情况)。

A sample image of the ktr would be like ktr的示例图片如下

在此处输入图片说明

My idea is to read all the files first from the path and then filter out whatever files are required, instead of double checking the existance of the files. 我的想法是先从路径中读取所有文件,然后过滤掉所需的任何文件,而不是仔细检查文件的存在。

NB In the image above, path is the location of the image directory. 注意:在上图中,路径是映像目录的位置。 Use your own folder path to get the correct result. 使用您自己的文件夹路径以获得正确的结果。

Hope it helps:) 希望能帮助到你:)

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

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