Reputation: 4773
In a standard windows batch file (.cmd) I want to do:
FOR /F "skip=0" %%G IN (filename.txt) DO ( ECHO %%G )
but I get " was unexpected at this time.
"skip=1"
works fine (In my actual code 0
is a variable).
According to ss64.com the default is skip=0
, but it seems not to work when explicitly set.
Am I doing it wrong? Or is there a workaround I can use?
Edit:
I have tried this on both Windows server 2003 and Windows 7.
The content of filename.txt could be:
something
stuff
unicorns
Upvotes: 5
Views: 5614
Reputation: 1
I add a ""false"" first line to avoid the IF line(s) and keep the "skip" anytime :
:: liste des fichiers du repertoire et de ses sous-repertoires
echo *** liste des fichiers du repertoire et de ses sous-repertoires >%FicListImg%
dir /s /b /a:-d %RepImg%\*.* >> %FicListImg%
set compteurA=0
for /f %%a in (%FicListImg%) do set /a CompteurA+=1
set /a CompteurA = %CompteurA%-1
set /a NbImg = %CompteurA%-1
@echo Repertoire Images : %RepImg% (%NbImg% images)
Upvotes: 0
Reputation: 354576
It really doesn't like the 0
, causing the parser to expect more after it (You can also trip it when trying to use 09
which it tries parsing as octal, which fails).
I guess you need to create an environment variable holding the entire skip=n
part or nothing and insert that into the argument list. Something like
if %N% GTR 0 (
set SKIP="skip=%N%"
) else (
set SKIP=
)
and then use
for /f %SKIP% %%G ...
(or without the quotes if you need to pass more options).
Upvotes: 6