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");