- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Concatenating large number of files
I am trying to concatenate several files in a folder as below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of files
Jump into JMP Scripting
By: Wendy Murphrey and Rosemary Lucas
// http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=61733
Page 122, Soultion 5.16
Set Current Directory( "C:\temp2" );
myFiles = Files In Directory( "C:\temp2" );
For( i = 1, i <= N Items( myFiles ), i++,
/* 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( "C:\temp2\" || myFiles ),
dt = Open( "C:\temp2\" || myFiles );
mainDt = mainDt << Concatenate( dt, Append to First Table );
Close( dt, NoSave );
Wait( 0 );
)
);
/* Give the final table a name. */
mainDt << Set Name( "Concatenated Files" );
Best regards,
-Matt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of files
Jump into JMP Scripting
By: Wendy Murphrey and Rosemary Lucas
// http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=61733
Page 122, Soultion 5.16
Set Current Directory( "C:\temp2" );
myFiles = Files In Directory( "C:\temp2" );
For( i = 1, i <= N Items( myFiles ), i++,
/* 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( "C:\temp2\" || myFiles ),
dt = Open( "C:\temp2\" || myFiles );
mainDt = mainDt << Concatenate( dt, Append to First Table );
Close( dt, NoSave );
Wait( 0 );
)
);
/* Give the final table a name. */
mainDt << Set Name( "Concatenated Files" );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of files
After logging in, "reply" to the posting and "Quote Original". You will the have the complete code which you can copy / paste into a JMP script window. Then remove the first 2 characters on each line ("> ") to get the code as it was intended. Then cancel the reply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of files
Thanks, mpb for the tip.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of files
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");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of 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");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenating large number of files
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