what's wrong with this loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
doscode
Posts: 174
Joined: 15 Feb 2012 14:02

what's wrong with this loop

#1 Post by doscode » 05 Jun 2012 04:47

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.

dbenham
Expert
Posts: 1961
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: what's wrong with this loop

#2 Post by dbenham » 05 Jun 2012 05:11

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

doscode
Posts: 174
Joined: 15 Feb 2012 14:02

Re: what's wrong with this loop

#3 Post by doscode » 05 Jun 2012 05:36

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

Squashman
Expert
Posts: 3667
Joined: 23 Dec 2011 13:59

Re: what's wrong with this loop

#4 Post by Squashman » 05 Jun 2012 06:14

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

Post Reply