Page 1 of 1

what's wrong with this loop

Posted: 05 Jun 2012 04:47
by doscode
It should print all xml files

Code: Select all

Setlocal EnableDelayedExpansion
@echo off
chcp 1250
FOR /f "delims=" %%x IN (delimiter.ini) DO set TAB=%%x
FOR %%F IN ('dir *.xml /b /o:n') DO (
set file=%%~nF
echo "!file!"
echo %tab%!file!>> files.txt
REM md "!file!"
)
pause


But starts with:

Code: Select all

   'dir

and ends with

Code: Select all

   b
   o:n'

the files are not ordered correctly (having diacritics inside)

I want to get just list of files (no extension) and write it into file.

Re: what's wrong with this loop

Posted: 05 Jun 2012 05:11
by dbenham
You forgot the /F option in your second FOR. You probably also want "eol=: delims=" in case file name contains space(s) or starts with semicolon. You could set EOL to * or ? as well. It just needs to be some character that can never start a Windows file name or path.


Dave Benham

Re: what's wrong with this loop

Posted: 05 Jun 2012 05:36
by doscode
Oh. I it was originaly

FOR %%F IN (*.xml) DO ()

And it worked. So after changing to command and single quotes I did not realized the missing /F

Thanks

Re: what's wrong with this loop

Posted: 05 Jun 2012 06:14
by Squashman
I am still confused by doscode's use of a TAB or his problems using a TAB. Is this a language specific issue with his version of Windows?
Not sure why he is putting the delimiter into a file.

File1.txt

Code: Select all

Before1   After1
Before2      After2
Before3         After3
Before4            After4

delims.bat

Code: Select all

@echo off
set "tab=   "
REM Delims is a tab
(
FOR /F "Tokens=1,2 Delims=   " %%G in ('type File1.txt') do echo %%G%tab%%tab%%%H
)>File2.txt

File2.txt

Code: Select all

Before1      After1
Before2      After2
Before3      After3
Before4      After4