我有几个文件夹,每个文件夹中有几个CSV文件。 每个CSV文件约有500,000行。 我使用JSL脚本将每个文件夹内的所有csv文件连接到一个JMP表中。 在每个文件夹上都重复此过程,因此最终,连接的JMP表的数量与文件夹数量一样多。 但是需要很多时间。
我在JSL中搜索并行编程,并了解了并行分配。 我需要一些有关如何将脚本放在“并行分配”内部的指南,以加快串联速度。 我将不胜感激。
path = munger(Pick Directory( "Browse to the Directory of the .txt / .csv files " ),1,"/","");
Print(dirList(path));
folderlist={};
folderlist = dirList(path);
count=nitems(folderlist);
//prefolderlist = Files In Directory( path );
//filepath = Convert File Path(path, Windows )
For( j2 = 1, count >= j2, j2++,
folderpath= path || folderlist[j2] || "/" ;
Print(folderpath);
prefilelist = Files In Directory( folderpath );
n2=nitems(prefilelist);
filelist = {};
//filter out any non-txt or csv files
For( i2 = 1, n2 >= i2, i2++,
file=(prefilelist[i2]);
If( Item( 2, prefilelist[i2], "." ) == "txt" | Item( 2, prefilelist[i2], "." ) == "csv",
Insert Into( filelist,file),
show(file)
)
);
nf=nitems(filelist); //number of items in the working list
cctable= New Table( "Combined data table ");//make an empty table
cctable<<New Column( "Source", Character, Nominal );
For( iii = 1 , iii <= nf, iii++, //this starts the first loop
filenow = ( filelist[iii] );
fileopen=(folderpath||filenow);
//dt=open(fileopen,private);
dt=open(fileopen,importset,private);//Import settings used in the open argument
New Column( "Source", Character, Nominal );
:Source << set each value( filenow );
//dt<<new column("Source", character, nominal)<<set each value(9999);
dt << Run Formulas();
//add the current table to the bottom of the combined data table
cctable << Concatenate( Data Table( dt ), Append to first table );
//don't use "Create Source Column" argument
Close( dt, NoSave );//after concatenating the table, close it and move on
);//end of the first for loop
);看一下File-> MultipleFileImport。 它可以浏览嵌套目录,按文件名模式选择,并连接相似的文件。 它比在CSV上使用open()更快,通常甚至对于单个文件也是如此。 它还使您可以修改和重用脚本。 它可以添加带有源文件信息的列。
以交互方式开始,查找复选框以保持窗口打开,进行一些实验。
GUI有四个过滤器,用于选择选定的文件。文件夹/隐藏/递归过滤器始终可见,并且有三个复选框可以显示和使能文件名,文件时间和文件大小过滤器。 文件列表显示选择的内容。它是不用于选择文件。
最坏的情况是,您可以在每个目录上一次使用MFI,一次可以提高速度。 最好的情况是,它可以在整个目录嵌套中执行您想要的操作。
并行分配旨在填充数组,并运行JSL,以在隔离的环境中填充每个数组元素,以防止线程之间的错误。 它试图避免从两个不同的线程同时访问数据表之类的事情。 如果找到解决方法,它可能会崩溃。
非常感谢。 我能够在脚本中合并“导入多个文件”,现在它可以更快地连接表。