K
K
KTG2019-03-15 04:35:39
cmd/bat
KTG, 2019-03-15 04:35:39

How to make a config for CMD/BAT with an array of parameters?

The situation is this, once every N days TXT files are sent.
You need to upload them to the database.
At the moment, it works for me like this: The batch file looks in a loop for all txt files in the specified directory, takes their names, and simply calls the appropriate script: test.txt launches test.sql and test.ctl. Both files are described manually. But I want to get rid of them.
I want to describe the structure of the tables in the config file, so that the batch file itself would generate scripts for sql and ctl and could be corrected at any time. So that you can take an array of the database structure from it and work with it in a bat-nickname.
As a result, get a settings file, something like this:

### Main settings
------------------------------------------
DataOutDir=./Out
LogDir=./Logs

### Tables
------------------------------------------
Tables[1][Name]=Collections
Tables[1][Comment]="Таблица коллекций"

   Tables[1][F1][Name]=Id
   Tables[1][F1][Type]=Number
   Tables[1][F1][Comment]="Идентификатор"

   Tables[1][F2][Name]=Name
   Tables[1][F2][Type]=Varchar2(100)
   Tables[1][F2][Comment]="Наименование"

Tables[2][Name]=Categories
Tables[2][Comment]="Таблица категорий"

   Tables[2][F1][Name]=Id
   Tables[2][F1][Type]=Number
   Tables[2][F1][Comment]="Идентификатор"

   Tables[2][F2][Name]=Name
   Tables[2][F2][Type]=Varchar2(100)
   Tables[2][F2][Comment]="Наименование"

   Tables[2][F3][Name]=Parent_cat
   Tables[2][F3][Type]=Varchar2(100)
   Tables[2][F3][Comment]="Родительская категория"

Well, the essence of the question: how to be?
I found examples of a regular settings file on the Internet, but it's not clear what to do with arrays.
Or maybe someone has a more interesting option?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2019-03-15
@KTG

There are no arrays in cmd, but you can simulate them by generating a variable name on the fly: where the variables IDX1 and IDX2 contain the corresponding indices. Instead of indexes, you can use, for example, field names from the config. If the structure is large enough, then there will be many variables. In my opinion, this is some kind of dead end option. Even simpler: write the config in the format of declaring variables for cmd (i.e. set "Tables_2_f1_name=Id") give the file a bat or cmd extension (or copy the config to bat/cmd before launch) and just call it as a nested batch file: call config .bat If you do not specify the set command directly in the config, then you cannot directly call it via call, but you can read the config line by line in a simple loop and substitute it into the set command.
Perhaps it would be easier to filter the config for each line of data from the file using findstr,
selecting the desired line. After the first filtering, the config will be cached and subsequent filtering will be faster.
Or, if the structures rarely change, just sew them into the batch file code.

S
sergey, 2019-03-18
kuzmin @sergueik

maybe use powershell. it is very slow, but it has arrays and "programming is possible".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question