你好,有人可以幫我修改這段程式碼嗎?我正在嘗試連接每個資料夾的 csv 檔案。 使用者必須選擇一個資料夾,所有符合條件的 csv 資料夾將根據資料夾名稱連接並儲存。 此方法使用戶在每次腳本運行時選擇一個資料夾。
但是,我現在想做的是讓使用者選擇主資料夾,然後運行腳本並連接每個子資料夾的資料(像前面的方法一樣,用資料夾名稱作為檔案名稱單獨保存它們)。
但透過這些程式碼,所有 csv 檔案都被連接成一個檔案。 你能幫忙修改和解釋遞歸是如何運作的嗎? 如何透過開啟主資料夾來單獨保存這些檔案(連接每個資料夾的資料)。 我正在使用 JMP 15。 謝謝
p = pick Directory("Select a Folder");<BR />//f = Files In Directory(p);
f = Files In Directory(p, recursive(1));
Dir = Word(-1, p, "/"); //get filename
saveDir = Substr( p, 1, Length( p ) - Length( Word( -1, p, "\/" ) ) - 1 ); //save file outside main folder
/* Removes the file names from the list f which are not CSV files */
for(j=1,j<=N Items(f),j++,
If (Substr(f[j],Length(f[j])-2,3)!= "CSV",
RemoveFrom(f,j,1);
j=j-1;
);
);
A = {}; /* creates a empty list for storing the names of each data table */
B = {};
C = {};
D = {};
k = {};
m = {};
/*Opens each one of the CSV files and deletes all unwanted rows */
for(j=1,j<=N Items(f),j++,
CSV = Open(Concat(p,f[j]), End of Field(comma), Strip Quotes(1), Labels(1),
Column Names Start(3), Data Starts(4), Columns(:MRR=Numeric));
colname = {};
colname = CSV<<GET column="" names="">20 & Contains(colname,"Weight")>50,
InsertInto(A,CSV);
CSV<<SELECT where="">1,
dt2 = dt1<<CONCATENATE>1,
dt3 = dt1<<CONCATENATE></CONCATENATE></CONCATENATE></SELECT></GET>