user1171858
user1171858

Reputation: 31

Windows Batch Script : for loop not printing * values

I have a batch script line like below :

for %%v in (aa bb* cc) do echo mget %%v

I am getting output as :

mget aa

mget cc

But I need output as :

mget aa 

mget bb*

mget cc

Update

I have a batch file called ftp.bat and a parameter file called parm.txt. parm.txt looks like:

server=xxx.yyy.com
user=abc
pwd=xyz
files=aa bb* cc dd ------(this varies)

I need to extract these values in my batch file to construct ftp commands. Using delim concept I've got server, user, pwd but I need to separate the files.

Upvotes: 2

Views: 804

Answers (1)

arx
arx

Reputation: 16896

If you use for with a wildcard, the interpreter looks for all files matching the wildcard ("bb*" in this case) and passes the names of the files to your command. It won't pass a string containing a '*' (or a '?') to your command.

Instead, create a text file called filelist.txt containing:

aa
bb*
cc

and use the command:

for /F %%I in (filelist.txt) do echo mget %%I

Update

Apparently, there is already a filelist.txt with multiple items on each line. Create a batch file called vary.bat:

@echo off
:more
if "%1"=="" (goto finished)
echo mget %1
shift
goto more
:finished

This takes a variable number of parameters and echoes an mget for each one. Call it with something like:

for /F "tokens=*" %%I in (filelist.txt) do vary %%I

Another update

This will read parm.txt, create a variable for each of server, user, pwd and files, then call vary.bat (described above) on the list of files.

for /F "delims== tokens=1,2" %%I in (parm.txt) do set %%I=%%J
vary %files%

Upvotes: 4

Related Questions