T
Tuomas Järvinen
Hi There!
I'm creating a batch file for creating number of new users . It reads config
and data file. The data file is normal CSV file.
first we read config file for data colum names:
@echo off
setlocal
type a.x | find /i "datacolumn" > a2.x
set count=0
set max=0
set inc=1
for /f "eol=# " %%a in ( a2.x ) do
for /f "tokens=1,* delims==" %%g in ("%%a") do (
set %%g=%%h
set %%h=XXX
set /a COUNT+=%inc%
)
)
echo Read %COUNT% columns.
Works fine: I can get datacolun=name and name=XXX from file a2.x.
On second stage we should parse the data from CSV file and put the field to
named variable. (Finally I should have each data field in named variables
so I can - for example - create a new user with net user %username% /add
/domain command).
Here is pseudo-code how I try to do this:
set count = 0 - init counter
loop line in file - loop line by line
set count inc 1 - inc counter
loop pos to Max - loop position to max
loop pos-item in line max - walk each field in line
if item="" item = XXX - if its empthy, put XXX
named=item - save item
endloop
endloop
Do-the-work-here
endloop
End.
And now the code:
set count=0
set pos=0
for /F "eol=#" %%a in ( b.x ) do (
set /a count=%count%+%inc% do (
echo Debug: Line %count%
for /L %%y in (1,1,%MAX) do (
for /F "tokens=%%y delims=;" %%i in ("%%a" ) do (
rem .... do the stuff here, we have now line field %%i from line %%a
rem in %named% variable.
)
)
)
I get error "-10 delims=;" was unexpected at this time." for line
starting with 'for /F "tokens=%%y....' (I suppose...)
If someone can help and/or give some better clue/point/idea..
Reason why I don't use win2k standard import tools (csvde for example), they
does not create and grant permissions home directories, .
Thank you for help.
- Tuomas.
mtjjarvin at yahoo dot com
I'm creating a batch file for creating number of new users . It reads config
and data file. The data file is normal CSV file.
first we read config file for data colum names:
@echo off
setlocal
type a.x | find /i "datacolumn" > a2.x
set count=0
set max=0
set inc=1
for /f "eol=# " %%a in ( a2.x ) do
for /f "tokens=1,* delims==" %%g in ("%%a") do (
set %%g=%%h
set %%h=XXX
set /a COUNT+=%inc%
)
)
echo Read %COUNT% columns.
Works fine: I can get datacolun=name and name=XXX from file a2.x.
On second stage we should parse the data from CSV file and put the field to
named variable. (Finally I should have each data field in named variables
so I can - for example - create a new user with net user %username% /add
/domain command).
Here is pseudo-code how I try to do this:
set count = 0 - init counter
loop line in file - loop line by line
set count inc 1 - inc counter
loop pos to Max - loop position to max
loop pos-item in line max - walk each field in line
if item="" item = XXX - if its empthy, put XXX
named=item - save item
endloop
endloop
Do-the-work-here
endloop
End.
And now the code:
set count=0
set pos=0
for /F "eol=#" %%a in ( b.x ) do (
set /a count=%count%+%inc% do (
echo Debug: Line %count%
for /L %%y in (1,1,%MAX) do (
for /F "tokens=%%y delims=;" %%i in ("%%a" ) do (
rem .... do the stuff here, we have now line field %%i from line %%a
rem in %named% variable.
)
)
)
I get error "-10 delims=;" was unexpected at this time." for line
starting with 'for /F "tokens=%%y....' (I suppose...)
If someone can help and/or give some better clue/point/idea..
Reason why I don't use win2k standard import tools (csvde for example), they
does not create and grant permissions home directories, .
Thank you for help.
- Tuomas.
mtjjarvin at yahoo dot com