How to set Optional Parameters in Batch Window for importing Data using ASCII

I want to import .txt files using Batch Window. After referring the user manual and reading other related posts in the forum ,I could make a sucessful attempt in importing the same.

However, everyday I get three EOD files in the format of ".txt" which have specific dates. Is it possible to import all the ".txt" files at once using the batch process? or Choose specific date for the batch process to pickup specific ".txt" file.

I see that new version 6.35 introduced the optional parameters in Batch window. But I don't know if it serves the purpose.

Example of Text file format which I get everyday and are saved in the same folder: -

  1. Eod-Cash-26-03-2020.txt
  2. Eod-Futures-26-03-2020.txt
  3. Eod-Indices-26-03-2020.txt
<?xml version="1.0" encoding="ISO-8859-1"?>
<AmiBroker-Batch CompactMode="0">
<Step>
<Action>ImportASCII</Action>
<Param>D:\\Macros\\Output\\EOD.txt</Param>
<Param2/>
</Step>
</AmiBroker-Batch>

What prevents you from creating three AB batch import steps/tasks (use different file names without date and then save to AB batch file)?

Also it is not clear whether your files have very same format and whether they have a symbol name column (I guess).


If they all have same format and if they all have a symbol name column then you could merge those files by same file extension via Windows batch file before import.

Content of batch file (.bat file extension) e.g.:

copy "C:\ABimport\*.txt" "C:\ABimport\import_file.txt"

Batch file name e.g. merge.bat (location of that bat file -> same folder as your single data files).

Then your first AB batch step would be Execute and Wait to execute that .bat file.
9


Alternatively (to creating .bat file) you could insert batch command directly into Execute and Wait Parameter/File field of AB batch:

cmd /c copy "C:\ABimport\*.txt" "C:\ABimport\import_file.txt"

9


Next AB batch step would be Data import ASCII to import merged data of import_file.txt file which contains the data of all of your three or more single data files.

3 Likes

Thank you so much sir. I never thought of merging the text files

1.I could add Three AB batch import steps but it's not possible to save the three text files without dates. It's the date which distinguishes the text files ( Though all of them have the same Columns with different tickers ) otherwise I may land in trouble importing the wrong file.

2.I tried the below and it's working. I have to add the delete bat file after importing , because the merged text file is not getting overwritten when i run the code for second time for another date.

  1. Out of curiosity to learn what would be the CMD line for the Merge and Delete parts

I Tried CMD Prompt but it's not working

cmd /d copy "D:\Macros\Output\*.txt" "D:\Macros\Output\import_file.txt"

Bat file is working

<?xml version="1.0" encoding="ISO-8859-1"?>
<AmiBroker-Batch CompactMode="0">
<Step>
<Action>ExecuteAndWait</Action>
<Param>D:\\Macros\\Output\\Merge.bat</Param>
<Param2/>
</Step>
<Step>
<Action>ImportASCII</Action>
<Param>D:\\Macros\\Output\\import_file.txt</Param>
<Param2/>
</Step>
<Step>
<Action>ExecuteAndWait</Action>
<Param>D:\\Macros\\Output\\Delete.bat</Param>
<Param2/>
</Step>
</AmiBroker-Batch>

To delete a file e.g.

cmd /c del "C:\ABimport\import_file.txt" 

9

To delete read only files e.g.

cmd /c del /f "C:\ABimport\import_file.txt" 

/f to force deletion of read-only files