Hi, can someone help me modify this code? I am trying to concatenate csv files per folder. The user will have to select a folder and all the qualified csv folders will be concatenated and be saved according to the folder name. This method makes user pick one folder per script run.
However, what I am trying to do now is to make the user pick the main folder then run the script and concatenate the data per subfolders (saving them individually with its folder name as the filename like in the previous method).
But with these code, all the csv files are being concatenated into one file. Can you help modify and explain how recursive works? And how can I save this files individually (concatenate data per folder) with just opening the main folder. I am using JMP 15. Thank you
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>