vendredi 27 juillet 2018

If statement: test delayedexpansion !counter! variable inside if condition

I can't reference !count! inside the for loop, and if I reference it as %count%, then it simply is set to 1 (what it was before entering the loop).

setlocal enableextensions enabledelayedexpansion
FOR /F "tokens=*" %%a in ('returnNumLines.bat apiKey.txt') do SET numKeys=%%a
FOR /F "tokens=*" %%a in ('returnLine.bat %numKeys% apiKey.txt') do SET APIKEY=%%a

set dbName=somedb
set tableName=ur_table
set PGPASSWORD=1234
REM counter
set /a count = 1

echo CREATE TABLE temp_table (symbol varchar(8), timestamp date, open real, high real,low real,close real,adjusted_close real,volume real,dividend_amount real,split_coefficient real,CONSTRAINT temp_pkey PRIMARY KEY (timestamp,symbol)) WITH (OIDS=FALSE) TABLESPACE pg_default;ALTER TABLE temp_table OWNER to postgres; | psql -U postgres %dbName%

for /F "delims=;" %%a in (c:\test\nasdaqSymbolsNoHeader.csv) do (

    set /a count +=1

    ...

    IF "!count!"=="%numKeys%" (SET /a count=1)


)

echo drop table temp_table;| psql -U postgres somedb
endlocal

Aucun commentaire:

Enregistrer un commentaire