I made a variation of that code that incorporates the Source table name for each file. In this case it takes all the txt files but you can also do it with csv or other format.
mypath ="C:\temp\";
Set Current Directory( mypath );
y = Files In Directory( mypath );
For( i = N Items( y ), i > 0, i--,
If( Ends With( y[i], "txt" ),
,
Remove From( y, i )
)
);
n = N Items( y );
For( i = 1, i <= N Items( y ), i++,
sname=left(y[i],length(y[i])-4);
/* If the file is the first in the list, open it. Otherwise, open the table, concatenate with the main table, and close the table just opened. */
If( i == 1,
mainDt = Open( mypath || y[i] );
mainDt << New Column ("source", character, set each value ( sname )),
dt = Open( mypath || y[i] ) ;
dt << New Column ("source", character, set each value ( sname ));
mainDt = mainDt << Concatenate( dt, Append to First Table );
Close( dt, NoSave );
Wait( 0 );
)
);
/* Give the final table a name. */
mainDt<< Set Name("Concatenated Files");
I am hoping to find out where I am going wrong with this one. The debugger won't start but I have about 20,000 files, could that be the problem?
Set Current Directory( mypath );
y = Files In Directory( mypath );
For( i = N Items( y ), i > 0, i--,
If( Ends With( y[i], "csv" ),
,
Remove From( y, i )
)
);
n = N Items( y );
For( i = 1, i <= N Items( y ), i++,
sname=left(y[i],length(y[i])-4);
/* If the file is the first in the list, open it. Otherwise, open the table, concatenate with the main table, and close the table just opened. */
If( i == 1,
mainDt = Open( mypath || y[i] );
mainDt << New Column ("source", character, set each value ( sname )),
dt = Open( mypath || y[i] ) ;
dt << New Column ("source", character, set each value ( sname ));
mainDt = mainDt << Concatenate( dt, Append to First Table );
Close( dt, NoSave );
Wait( 0 );
)
);
/* Give the final table a name. */
mainDt<< Set Name("Terminal");
hi @mjvincent87
The original post is several years old and some better options exist for importing multiple files from a directory.
Have you seen the multiple file import that was introduced in JMP 14?
The new multiple file import platform launches a dialog to load several files into a single JMP data table. In addition, it allows filtering of files by size, date, name and type and supports one-column import, useful for Text Explorer document preparation. Also the platform offers support for editing text import options.
cheers,
Stan