Import multiple files via - OLE

Hi,

I am trying to import multiple files via OLE mode. I am able to import one file at a time but not all files at the same time. below is the code I am using

Public FileName as String
Public ABK as Object
Public ABKPath as String

Sub Amibkf()

FileName = "E:\Files" & "File1" & ".txt"
Set ABK = CreateObject("Broker.Application")
ABK.Visible= True
Call ABK.Import (0,FileName,"Old.format")
Call ABK. RefreshAll
ABK. SaveDatabase
End Sub

Can somone please guide me on how to import multiple file at once using the above method.

Hello

The BEST way to import multiple files is, by using the batch functionality of AmiBroker.

https://www.amibroker.com/guide/h_batch.html

If you download your data automatically using InternetOpenURL(), then you may use this custom function to replace the header of the file automatically and then amibroker batch will take care of every single different format of your data ASCII files.

If you are In the chart window you can make a Gui* button or ParamTrigger() to call the job that you already made, and save in batch window using the ShellExecute() function

// run batch
trigger  = ParamTrigger( "runbatch Import ASCII ", " Press Once" );
if( trigger  )
{
    ShellExecute( "runbatch", "C:\\AmiBroker\\Batch\\My_Eod_data.abb", "" );
}

i quickly search the forum and i found a thread you may need to read

Now if you still like to use the old version OLE below are two examples

// Script created: 15.12.2008 08:01   Author: Panos B
// import multiple specific files that they have the same format 
//  


// database 
 var intradatabase="E:\\Ami-Data\\LAN";  //**** replace the path with your database folder

AmiBroker = new ActiveXObject( "Broker.Application" );

// open database
 // AmiBroker.LoadDatabase (intradatabase);  // uncomment this line to loaddatabase if you need it 
 

 if( ! AmiBroker.Import( 0, "C:\\TEMP\\AUDUSD.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\Crude_Oil.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\DAX_30.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\Dow_Jones.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\EURUSD.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\FTSE_100.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\GBPJPY.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\GBPUSD.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\Gold.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\Nasdaq_100.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\S&P_500.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\Silver.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\USDCAD.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\USDCHF.csv","GCI_noname.format" ));
 if( ! AmiBroker.Import( 0, "C:\\TEMP\\USDJPY.csv","GCI_noname.format" ));

WScript.Echo( "import is finished OK."  );
// AmiBroker.RefreshAll();

//AmiBroker.Visible(1);  // open amibroker if it is close

below Java file i donot remember where i found it but is tested and working also

// Here you have an example to import multiple files that are part of same folder and have same format.
//jscript to import all data files of a folder fitting set format (of format file)
// please you MUST edit the lines with the stars //	*********

// database to save the imported data
var intradatabase="E:\\Ami-Data\\LAN"; 	//	*********

var AmiBroker = new ActiveXObject( "Broker.Application" );

function Import( myfilename )
{
AmiBroker.Import( 0, myfilename, "YourFormat.format" ); //define format file *********
AmiBroker.RefreshAll();
}

// open database
  AmiBroker.LoadDatabase (intradatabase);
var dataFolder = "R:\\YourFolder\\";// set source data file(s) folder ***********

var fso, fh, fc, filename;

//FileSystemObject
fso = new ActiveXObject("Scripting.FileSystemObject");

// Iterate through all files in the folder
fh = fso.GetFolder( dataFolder );
fc = new Enumerator(fh.files);
for (; !fc.atEnd(); fc.moveNext())
{
filename = "" + fc.item();
Import(filename);
}

// AmiBroker.RefreshAll();   
AmiBroker.SaveDatabase();
//AmiBroker.Visible(1);  //  open amibroker if it is close

//notify user when import is finished
var Shell = new ActiveXObject("WScript.Shell");
Shell.Popup("Import Completed /DataBase Saved", 1.5);

I repeat one more time

The BEST way to import multiple files is, by using the batch functionality of AmiBroker.

5 Likes

The loop code is by Tomasz Janeczko and has been posted here at old forum:
https://groups.yahoo.com/neo/groups/amibroker/conversations/messages/180840
(and it's JavaScript not Java)

3 Likes

Hello @fxshrat you did a nice job as usually :heart_eyes:

Hi PanoS, Thanks for the detailed reply, I tried your java code and it worked fine. :slight_smile:

1 Like

Hi Fxshrat, thanks for the reply ! the Java code worked fine! :slight_smile:

Hi @fxshrat, seems like this is what I have been looking for, but as yahoo groups have been discontinued, I am not able to access the content on the link. Could you please maybe share again the same and also how to use it?

@harshitsinghal - Sherlock look UP, the code is in this very thread. Reading is lost art.

1 Like

Sorry missed it, unfortunately it was not what I was looking for. The code is for multiple files but I need to import multiple folders having multiple csv files with quotation data.