Reputation: 13
im having a very weird problem with my csv files. I try to get as output the data before the first coma, it works with every files except one.
it's this one (with different alias and name ofc)
dbackup_support,Support AdBackup,0
admin.zoom,admin.zoom,0
Administrateur,Administrateur,0
jsmith,john smith,266
jsmith1,john smith1,266
jsmith1,john smith1,12
jsmith1,john smith1,4232
jsmith1,john smith1,243
jsmith1,john smith1,532524
so with this code :
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "tokens=1 delims=," %%A in (Liste_mailboxes.txt) do (
set var1=%%A
echo !var1!
pause
)
pause
it wont even go in the loop
while with this file it wiill work
jsmith1,23/10/2017 20:58
jsmith2,23/10/2017 21:00
jsmith3,23/10/2017 20:59
jsmith4,23/10/2017 21:15
jsmith5,23/10/2017 21:26
jsmith6,23/10/2017 21:05
jsmith7,23/10/2017 21:47
do you have any idea what i have done wrong ? thank you and sorry for bad english
edit : i have found more weird thing, if i copy past what is in the file into a new one it will work. But if i do a copy of it, it wont work. I really dont know whats wrong with this file.
Upvotes: 0
Views: 31
Reputation: 56180
I guess, your first text file has a Unicode encoding. Some batch commands (like for
) do have problems with that. Type
converts the encoding to Ansi "on the fly", so you can:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1 delims=," %%A in ('type Liste_mailboxes.txt') do (
set var1=%%A
echo !var1!
pause
)
Note if you don't to anything to var
, you can just use %%A
instead:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1 delims=," %%A in ('type Liste_mailboxes.txt') do (
echo %%A
pause
)
Upvotes: 1