For loop CSV empty value

April 20, 2009 at 06:28:46
Specs: Windows XP
I am using a CSV file to import users into active directory.

Example CSV:

Surname,First Name,Middle Name,Date of Birth,Student Number,Description

I can extract all the information I need using the following statement;

FOR /F "tokens=1,2,3,4,5,6* delims=," %%A IN (users.csv) DO (

That is until a field is empty, for example no middle name;

Surname,First Name,,Date of Birth,Student Number,Description

The empty value is ignored, not counted as a token which breaks my dsadd user variables.

What can I do, I am stuck!?


See More: For loop CSV empty value

Report •

April 20, 2009 at 07:32:48
:: chg ,, to , , to keep blank fields working

@echo off > new.csv & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (old.csv) do (
set str=%%a
set str=!str:,,=, ,!
echo !str! >> new.csv

If at first you don't succeed, you're about average.


Report •
Related Solutions

Ask Question