Hi all,
I'm a scripting idiot and need a hand for accomplishing a simple task. I need a script that allows a user to select a single directory, looks for CSV files in the directory, and appends/concatenates the files into a single JMP datatable. For now, it's fine if this "master datatable" gets rebuilt with the CSV files in the directory every time the user runs the script.
I did some research and found something from resident super-user genius txnelson that should accomplish the task, but when I run it, I receive an error and I don't understand why. The script:
Names Default To Here( 1 );
// Setup an empty table to start to concatenate other tables to
dtbase = New Table( "Base Table" );
// Have the user select the starting folder
dirpath = Pick Directory( "Pick the Top Level Directory" );
// Get all of the files in all of the folders that are under the picked folder
TheFileList = Files In Directory( dirpath, "recursive" );
// Go through all of the files and read in append those that meet your
// requirement. You will need to amend the IF statement to meet your criteria
For( i = 1, i <= N Items( TheFileList ), i++,
If( Uppercase( Word( -1, TheFileList, "." ) ) == "CSV" & Is File( dirpath || TheFileList ) == 1,
dt = Open( dirpath || TheFileList );
dtbase = dtbase << concatenate( dt, append to first table( 1 ) );
Close( dt, nosave );
);
);When I run the script, it runs until I select the directory, and then nothing happens. I stepped through the code and here is where the error is thrown:
argument should be character in access or evaluation of 'Word' , Bad Argument( TheFileList ), Word/*###*/(-1, TheFileList, ".")
I don't understand what this jargon means. The code seems to make sense. Why won't it work?
Thanks and sorry for being an idiot.
Glad you figured it out, sorry for the trouble, and I can explain. Shortly after Jim Nelson posted that code, the JMP community went through a major conversion. The problem you ran into is one that I'm still catching in my old blog posts: sometimes the conversion process dropped the subscripts from JSL embedded in a post. (If you look further down in Jim's post, you can see a picture someone captured that includes the subscript...it really was right for a few months!)
@txnelson @Jeff_Perkinson
ancient post
Solved the problem by doing some more research--I guess there needs to be a little "i" encased in brackets to cycle through the different files picked up by Files in Directory, which was assigned to TheFileList. I don't even know where to begin--had no idea one could cycle through "items" like this--wouldn't even know where to find this function in the 700+page JSL guide. Scripting is impossible.
If( Uppercase( Word( -1, TheFileList[i], "." ) ) == "CSV" & Is File( dirpath || TheFileList[i] ) == 1,
dt = Open( dirpath || TheFileList[i] );
dtbase = dtbase << concatenate( dt, append to first table( 1 ) );
Close( dt, nosave );
);
);