连接大量文件嗨,大家好,
我正在尝试连接文件夹中的多个文件,如下所示:
回复:连接大量文件我认为这里有一个 JSL 错误
If( Ends With( y[i], "csv" ),
0 // need something here, a zero is good enough
,
Remove From( y, i )
)
两个相邻的逗号之间需要添加一些内容。0 是一个非常小的表达式,其计算结果为 0,不执行任何其他操作。(或者,也可以使用 !EndsWith(...) 来转换逻辑,其中 ! 表示“非”。)
回复:连接大量文件听起来不错,不幸的是我正在使用 JMP13回复:连接大量文件你好@mjvincent87
原始帖子已有数年历史,并且存在一些从目录导入多个文件的更好的选择。
您见过 JMP 14 中引入的多文件导入功能吗?
全新的多文件导入平台会启动一个对话框,将多个文件加载到单个 JMP 数据表中。此外,它还支持按大小、日期、名称和类型筛选文件,并支持单列导入,这对于文本探索器文档的准备非常有用。该平台还支持编辑文本导入选项。
干杯,
斯坦
回复:连接大量文件我希望找出这个问题的症结所在。调试器无法启动,但我有大约 20,000 个文件,这可能是问题所在吗?
Set Current Directory( mypath );
y = Files In Directory( mypath );
For( i = N Items( y ), i > 0, i--,
If( Ends With( y[i], "csv" ),
,
Remove From( y, i )
)
);
n = N Items( y );
For( i = 1, i <= N Items( y ), i++,
sname=left(y[i],length(y[i])-4);
/* If the file is the first in the list, open it. Otherwise, open the table, concatenate with the main table, and close the table just opened. */
If( i == 1,
mainDt = Open( mypath || y[i] );
mainDt << New Column ("source", character, set each value ( sname )),
dt = Open( mypath || y[i] ) ;
dt << New Column ("source", character, set each value ( sname ));
mainDt = mainDt << Concatenate( dt, Append to First Table );
Close( dt, NoSave );
Wait( 0 );
)
);
/* Give the final table a name. */
mainDt<< Set Name("Terminal");
回复:连接大量文件我对该代码做了一些修改,将源表名添加到每个文件中。在本例中,它会获取所有 txt 文件,但您也可以使用 csv 或其他格式。
mypath ="C:\temp\";
Set Current Directory( mypath );
y = Files In Directory( mypath );
For( i = N Items( y ), i > 0, i--,
If( Ends With( y[i], "txt" ),
,
Remove From( y, i )
)
);
n = N Items( y );
For( i = 1, i <= N Items( y ), i++,
sname=left(y[i],length(y[i])-4);
/* If the file is the first in the list, open it. Otherwise, open the table, concatenate with the main table, and close the table just opened. */
If( i == 1,
mainDt = Open( mypath || y[i] );
mainDt << New Column ("source", character, set each value ( sname )),
dt = Open( mypath || y[i] ) ;
dt << New Column ("source", character, set each value ( sname ));
mainDt = mainDt << Concatenate( dt, Append to First Table );
Close( dt, NoSave );
Wait( 0 );
)
);
/* Give the final table a name. */
mainDt<< Set Name("Concatenated Files");
回复:连接大量文件回复:连接大量文件谢谢Matt,这很有效。我会看看这本书。
谢谢 mpb 提供的提示。回复:连接大量文件你可能会发现这个技巧很有用:
登录后,回复该帖子并“引用原文”。您将获得完整的代码,可以将其复制/粘贴到 JMP 脚本窗口中。然后删除每行的前两个字符(“>”)以获取预期的代码。然后取消回复。回复:合并大量文件谢谢。请使用以下方式发布您的代码。
回复:连接大量文件看:
进入 JMP 脚本
作者:温迪·墨菲和罗斯玛丽·卢卡斯
// http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=61733
第 122 页,解决方案 5.16
设置当前目录(“C:\temp2”);
myFiles = 目录中的文件(“C:\temp2”);
对于(i = 1,i <= N 项(myFiles),i ++,
/* 如果文件是列表中的第一个,则打开它。否则,打开表,与主表连接,然后关闭刚刚打开的表。*/
如果(i == 1,
mainDt = 打开(“C:\temp2\”|| myFiles ),
dt = 打开(“C:\temp2\”|| myFiles );
mainDt = mainDt << Concatenate( dt, 附加到第一个表 );
关闭(dt,不保存);
等待(0);
)
(此处似有缺失,无法翻译);
/* 给最终的表格命名。 */
mainDt << 设置名称(“连接文件”);回复:连接大量文件看:
进入 JMP 脚本
作者:温迪·墨菲和罗斯玛丽·卢卡斯
// http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=61733
第 122 页,解决方案 5.16
设置当前目录(“C:\temp2”);
myFiles = 目录中的文件( “C:\temp2” );
对于(i = 1,i <= N 项(myFiles),i ++,
/* 如果文件是列表中的第一个,则打开它。否则,打开表,与主表连接,然后关闭刚刚打开的表。*/
如果(i == 1,
mainDt = 打开( “C:\temp2\” || myFiles ),
dt = 打开(“C:\temp2\”|| myFiles );
mainDt = mainDt << Concatenate( dt, 附加到第一个表 );
关闭(dt,不保存);
等待(0);
)
(此处似有缺失,请提供更正后的文本)。
/* 给最终的表格命名。 */
mainDt << 设置名称(“连接文件”);
此致,
-马特