我有幾個文件夾,每個文件夾中有幾個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,該JSL在隔離的環境中填充每個數組元素,以防止線程之間發生錯誤。 它試圖避免從兩個不同的線程同時訪問數據表之類的事情。 如果找到解決方法,它可能會崩潰。
非常感謝。 我能夠在腳本中合併“導入多個文件”,現在它可以更快地連接表。