如何让kettle遍历读取某个文件夹下的多个 xml文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何让kettle遍历读取某个文件夹下的多个 xml文件相关的知识,希望对你有一定的参考价值。

///
/// 遍历文件夹中所有的目标文件
///
/// 父文件路径
/// 目标文件名称
private void Swap(string path, string file)

string[] Floders = Directory.GetDirectories(path);
string[] Files = Directory.GetFiles(path, file);
foreach (string str in Files)

//str就你你要找的xml文件,要怎么处理自己去搞
MessageBox.Show(str);

foreach (string str in Floders)

Swap(str, file);


调用如下,假设你的ccmfile文件夹在C盘根目录
string path = "C:\\ccmfile";
Swap(path, "info.xml");
MessageBox.Show("完成!");
S
参考技术A ///
///
遍历文件夹中所有的目标文件
///
///
父文件路径
///
目标文件名称
private
void
Swap(string
path,
string
file)

string[]
Floders
=
Directory.GetDirectories(path);
string[]
Files
=
Directory.GetFiles(path,
file);
foreach
(string
str
in
Files)

//str就你你要找的xml文件,要怎么处理自己去搞
MessageBox.Show(str);

foreach
(string
str
in
Floders)

Swap(str,
file);


调用如下,假设你的ccmfile文件夹在C盘根目录
string
path
=
"C:\\ccmfile";
Swap(path,
"info.xml");
MessageBox.Show("完成!");
S

周报发送邮件KETTLE

技术图片

 

技术图片

 

 

 

 SELECT DISTINCT t2.xm_code,t2.xm_desc,t2.xm_contact,t3.user_email  FROM xm_main  t2
 LEFT JOIN   xm_agree_zb t1
 ON t2.xm_code =t1.xm_code 
 LEFT JOIN portal.t_acl_userinfo t3
 ON t2.xm_contact=t3.username
 WHERE t2.xm_code IS NOT NULL AND t2.xm_status NOT IN (项目完成,项目冻结) AND (t2.delete_status<>1 OR t2.delete_status IS NULL)
 AND (t1.input_date <=DATE_SUB(NOW(),INTERVAL 8 DAY) OR t1.input_date IS NULL)  AND t3.user_email IS NOT NULL AND t3.user_email <>‘‘ ORDER BY t2.xm_code DESC
//JavaScript脚本的代码
var
prevRowx=previous_result.getRows(); if (prevRowx == null &&(prevRowx.size()=0)) { false; }else{ parent_job.setVariable("prevRowx", prevRowx);////ArrayList存储表名变量 parent_job.setVariable("ht_Size", prevRowx.size());//存储执行文件的总数量 parent_job.setVariable("ht_Num", 0);//循环控制变量 parent_job.setVariable("sid", prevRowx.get(0).getString("xm_code","xm_code")); true; }

 

 技术图片

 

 

 

 SELECT t.USER_EMAIL mail_address   FROM portal.t_acl_userinfo AS t  WHERE t.username IN
(SELECT DISTINCT t1.xm_contact lxr FROM xm_main t1 WHERE t1.xm_code=${xm_code}) 
AND t.user_email IS NOT NULL AND t.user_email <>‘‘
//JavaScript

var p_mail_address = parent_job.getVariable("v_mail_address");

if(p_mail_address == null)
{
false;
}
else
{
true;
}
//累加器
var
list_dt_htbh =parent_job.getVariable("prevRowx").replace("[","").replace("]","").replace(" ","").split(","); var ht_Size = new Number(parent_job.getVariable("ht_Size")); var ht_Num = new Number(parent_job.getVariable("ht_Num"))+1; if(ht_Num<ht_Size){ parent_job.setVariable("xm_code", list_dt_htbh[ht_Num]); } parent_job.setVariable("ht_Num",ht_Num); true;

技术图片

 

将结果输出查看

技术图片

 

 

 技术图片

 

 

 

var list_dt_htbh =parent_job.getVariable("prevRowx");//这里没有去掉[]
var ht_Size = new Number(parent_job.getVariable("ht_Size"));
var ht_Num = new Number(parent_job.getVariable("ht_Num"))+‘1‘;
if(ht_Num<ht_Size){
    parent_job.setVariable("xm_code", list_dt_htbh[ht_Num]);
}
parent_job.setVariable("ht_Num",ht_Num);
true;

输出结果日志

2020/07/17 16:45:33 - Get Variables.0 - field [prevRowx] has value [[[201908KF-ZYFD01471], [201908KF-ZYFD0147], [201905KF-ZGYH0144], [201901KF-ZGYH0136], [201901KF-ZGYH0135], [201901KF-GJKF0164], [201309KF-ZGYH0001]]]
2020/07/17 16:45:33 - Get Variables.0 - Signaling ‘output done‘ to 1u8f93出 rowsets.
2020/07/17 16:45:33 - Get Variables.0 - 完成处理 (I=0, O=0, R=1, W=1, U=0, E=0
2020/07/17 16:45:33 - 字段选择.0 - 获取记录从前一个步骤: [undefined], [7], [0], [], [[[201908KF-ZYFD01471], [201908KF-ZYFD0147], [201905KF-ZGYH0144], [201901KF-ZGYH0136], [201901KF-ZGYH0135], [201901KF-GJKF0164], [201309KF-ZGYH0001]]]
2020/07/17 16:45:33 - 字段选择.0 - 写记录到下一个步骤: [undefined], [7], [0], [], [[[201908KF-ZYFD01471], [201908KF-ZYFD0147], [201905KF-ZGYH0144], [201901KF-ZGYH0136], [201901KF-ZGYH0135], [201901KF-GJKF0164], [201309KF-ZGYH0001]]]
2020/07/17 16:45:33 - 字段选择.0 - Signaling ‘output done‘ to 1u8f93出 rowsets.

 

以上是关于如何让kettle遍历读取某个文件夹下的多个 xml文件的主要内容,如果未能解决你的问题,请参考以下文章

kettle 从本地目录下读取文件,并按照文件名删除文件,如何实现

怎样用matlab读取一个文件夹下的多个子文件夹中的多个jpg图片,急用啊~~~

java 如何读取xml文件中的一个节点下的多个相同子节点

php 遍历文件夹文件问题

周报发送邮件KETTLE

Pentaho PDI/Kettle 从文本文件中读取多行